mirror of
https://github.com/TeamNewPipe/NewPipe.git
synced 2024-11-21 18:42:35 +01:00
Allow play/pausing from notification when buffering
This change is in line with a recent change in how the play/pause button behaves in the player ui: if the buffering indicator is shown, it's still possible to toggle play/pause, to allow e.g. pausing videos before they even start. This change was needed because on Android 13+ notification actions can't be null, and thus the buffering hourglass action wasn't shown.
This commit is contained in:
parent
17e88f1749
commit
4b1824e8c1
@ -40,12 +40,8 @@ public class SessionConnectorActionProvider implements MediaSessionConnector.Cus
|
||||
@Nullable
|
||||
@Override
|
||||
public PlaybackStateCompat.CustomAction getCustomAction(@NonNull final Player player) {
|
||||
if (data.action() == null) {
|
||||
return null;
|
||||
} else {
|
||||
return new PlaybackStateCompat.CustomAction.Builder(
|
||||
data.action(), data.name(), data.icon()
|
||||
).build();
|
||||
}
|
||||
return new PlaybackStateCompat.CustomAction.Builder(
|
||||
data.action(), data.name(), data.icon()
|
||||
).build();
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import static org.schabi.newpipe.player.notification.NotificationConstants.ACTIO
|
||||
import static org.schabi.newpipe.player.notification.NotificationConstants.ACTION_REPEAT;
|
||||
import static org.schabi.newpipe.player.notification.NotificationConstants.ACTION_SHUFFLE;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.DrawableRes;
|
||||
@ -23,21 +24,23 @@ import org.schabi.newpipe.player.Player;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class NotificationActionData {
|
||||
@Nullable
|
||||
|
||||
@NonNull
|
||||
private final String action;
|
||||
@NonNull
|
||||
private final String name;
|
||||
@DrawableRes
|
||||
private final int icon;
|
||||
|
||||
public NotificationActionData(@Nullable final String action, @NonNull final String name,
|
||||
|
||||
public NotificationActionData(@NonNull final String action, @NonNull final String name,
|
||||
@DrawableRes final int icon) {
|
||||
this.action = action;
|
||||
this.name = name;
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@NonNull
|
||||
public String action() {
|
||||
return action;
|
||||
}
|
||||
@ -52,6 +55,8 @@ public final class NotificationActionData {
|
||||
return icon;
|
||||
}
|
||||
|
||||
|
||||
@SuppressLint("PrivateResource") // we currently use Exoplayer's internal strings and icons
|
||||
@Nullable
|
||||
public static NotificationActionData fromNotificationActionEnum(
|
||||
@NonNull final Player player,
|
||||
@ -105,8 +110,7 @@ public final class NotificationActionData {
|
||||
if (player.getCurrentState() == Player.STATE_PREFLIGHT
|
||||
|| player.getCurrentState() == Player.STATE_BLOCKED
|
||||
|| player.getCurrentState() == Player.STATE_BUFFERING) {
|
||||
// null intent action -> show hourglass icon that does nothing when clicked
|
||||
return new NotificationActionData(null,
|
||||
return new NotificationActionData(ACTION_PLAY_PAUSE,
|
||||
ctx.getString(R.string.notification_action_buffering),
|
||||
R.drawable.ic_hourglass_top);
|
||||
}
|
||||
@ -171,7 +175,7 @@ public final class NotificationActionData {
|
||||
@Override
|
||||
public boolean equals(@Nullable final Object obj) {
|
||||
return (obj instanceof NotificationActionData other)
|
||||
&& Objects.equals(this.action, other.action)
|
||||
&& this.action.equals(other.action)
|
||||
&& this.name.equals(other.name)
|
||||
&& this.icon == other.icon;
|
||||
}
|
||||
|
@ -244,14 +244,8 @@ public final class NotificationUtil {
|
||||
return;
|
||||
}
|
||||
|
||||
final PendingIntent intent;
|
||||
if (data.action() == null) {
|
||||
intent = null;
|
||||
} else {
|
||||
intent = PendingIntentCompat.getBroadcast(player.getContext(), NOTIFICATION_ID,
|
||||
new Intent(data.action()), FLAG_UPDATE_CURRENT, false);
|
||||
}
|
||||
|
||||
final PendingIntent intent = PendingIntentCompat.getBroadcast(player.getContext(),
|
||||
NOTIFICATION_ID, new Intent(data.action()), FLAG_UPDATE_CURRENT, false);
|
||||
builder.addAction(new NotificationCompat.Action(data.icon(), data.name(), intent));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user