1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2025-09-09 06:16:00 +00:00

NavigationHelper: push out resumePlayback one layer

This commit is contained in:
Profpatsch
2025-05-04 20:56:27 +02:00
parent be66e8ce80
commit 395cea5165
2 changed files with 19 additions and 14 deletions

View File

@@ -256,7 +256,8 @@ public final class NotificationUtil {
} else { } else {
// We are playing in fragment. Don't open another activity just show fragment. That's it // We are playing in fragment. Don't open another activity just show fragment. That's it
final Intent intent = NavigationHelper.getPlayerIntent( final Intent intent = NavigationHelper.getPlayerIntent(
player.getContext(), MainActivity.class, null, true); player.getContext(), MainActivity.class, null);
intent.putExtra(Player.RESUME_PLAYBACK, true);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(Intent.ACTION_MAIN); intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.addCategory(Intent.CATEGORY_LAUNCHER);

View File

@@ -84,8 +84,7 @@ public final class NavigationHelper {
@NonNull @NonNull
public static <T> Intent getPlayerIntent(@NonNull final Context context, public static <T> Intent getPlayerIntent(@NonNull final Context context,
@NonNull final Class<T> targetClazz, @NonNull final Class<T> targetClazz,
@Nullable final PlayQueue playQueue, @Nullable final PlayQueue playQueue) {
final boolean resumePlayback) {
final Intent intent = new Intent(context, targetClazz); final Intent intent = new Intent(context, targetClazz);
if (playQueue != null) { if (playQueue != null) {
@@ -95,7 +94,6 @@ public final class NavigationHelper {
} }
} }
intent.putExtra(Player.PLAYER_TYPE, PlayerType.MAIN.valueForIntent()); intent.putExtra(Player.PLAYER_TYPE, PlayerType.MAIN.valueForIntent());
intent.putExtra(Player.RESUME_PLAYBACK, resumePlayback);
intent.putExtra(PlayerService.SHOULD_START_FOREGROUND_EXTRA, true); intent.putExtra(PlayerService.SHOULD_START_FOREGROUND_EXTRA, true);
return intent; return intent;
@@ -107,17 +105,19 @@ public final class NavigationHelper {
@Nullable final PlayQueue playQueue, @Nullable final PlayQueue playQueue,
final boolean resumePlayback, final boolean resumePlayback,
final boolean playWhenReady) { final boolean playWhenReady) {
return getPlayerIntent(context, targetClazz, playQueue, resumePlayback) return getPlayerIntent(context, targetClazz, playQueue)
.putExtra(Player.PLAY_WHEN_READY, playWhenReady); .putExtra(Player.PLAY_WHEN_READY, playWhenReady)
.putExtra(Player.RESUME_PLAYBACK, resumePlayback);
} }
@NonNull @NonNull
public static <T> Intent getPlayerEnqueueNextIntent(@NonNull final Context context, public static <T> Intent getPlayerEnqueueNextIntent(@NonNull final Context context,
@NonNull final Class<T> targetClazz, @NonNull final Class<T> targetClazz,
@Nullable final PlayQueue playQueue) { @Nullable final PlayQueue playQueue) {
// see comment in `getPlayerEnqueueIntent` as to why `resumePlayback` is false return getPlayerIntent(context, targetClazz, playQueue)
return getPlayerIntent(context, targetClazz, playQueue, false) .putExtra(Player.ENQUEUE_NEXT, true)
.putExtra(Player.ENQUEUE_NEXT, true); // see comment in `getPlayerEnqueueIntent` as to why `resumePlayback` is false
.putExtra(Player.RESUME_PLAYBACK, false);
} }
/* PLAY */ /* PLAY */
@@ -151,8 +151,9 @@ public final class NavigationHelper {
Toast.makeText(context, R.string.popup_playing_toast, Toast.LENGTH_SHORT).show(); Toast.makeText(context, R.string.popup_playing_toast, Toast.LENGTH_SHORT).show();
final Intent intent = getPlayerIntent(context, PlayerService.class, queue, resumePlayback); final Intent intent = getPlayerIntent(context, PlayerService.class, queue);
intent.putExtra(Player.PLAYER_TYPE, PlayerType.POPUP.valueForIntent()); intent.putExtra(Player.PLAYER_TYPE, PlayerType.POPUP.valueForIntent())
.putExtra(Player.RESUME_PLAYBACK, resumePlayback);
ContextCompat.startForegroundService(context, intent); ContextCompat.startForegroundService(context, intent);
} }
@@ -162,8 +163,9 @@ public final class NavigationHelper {
Toast.makeText(context, R.string.background_player_playing_toast, Toast.LENGTH_SHORT) Toast.makeText(context, R.string.background_player_playing_toast, Toast.LENGTH_SHORT)
.show(); .show();
final Intent intent = getPlayerIntent(context, PlayerService.class, queue, resumePlayback); final Intent intent = getPlayerIntent(context, PlayerService.class, queue);
intent.putExtra(Player.PLAYER_TYPE, PlayerType.AUDIO.valueForIntent()); intent.putExtra(Player.PLAYER_TYPE, PlayerType.AUDIO.valueForIntent());
intent.putExtra(Player.RESUME_PLAYBACK, resumePlayback);
ContextCompat.startForegroundService(context, intent); ContextCompat.startForegroundService(context, intent);
} }
@@ -176,6 +178,7 @@ public final class NavigationHelper {
} }
Toast.makeText(context, R.string.enqueued, Toast.LENGTH_SHORT).show(); Toast.makeText(context, R.string.enqueued, Toast.LENGTH_SHORT).show();
// when enqueueing `resumePlayback` is always `false` since: // when enqueueing `resumePlayback` is always `false` since:
// - if there is a video already playing, the value of `resumePlayback` just doesn't make // - if there is a video already playing, the value of `resumePlayback` just doesn't make
// any difference. // any difference.
@@ -183,8 +186,9 @@ public final class NavigationHelper {
// slightly different behaviour than the normal play action: the latter resumes playback, // slightly different behaviour than the normal play action: the latter resumes playback,
// the former doesn't. (note that enqueue can be triggered when nothing is playing only // the former doesn't. (note that enqueue can be triggered when nothing is playing only
// by long pressing the video detail fragment, playlist or channel controls // by long pressing the video detail fragment, playlist or channel controls
final Intent intent = getPlayerIntent(context, PlayerService.class, queue, false) final Intent intent = getPlayerIntent(context, PlayerService.class, queue)
.putExtra(Player.ENQUEUE, true); .putExtra(Player.ENQUEUE, true)
.putExtra(Player.RESUME_PLAYBACK, false);
intent.putExtra(Player.PLAYER_TYPE, playerType.valueForIntent()); intent.putExtra(Player.PLAYER_TYPE, playerType.valueForIntent());
ContextCompat.startForegroundService(context, intent); ContextCompat.startForegroundService(context, intent);