Skip to content

Commit

Permalink
Fix enqueuing behavior related to TeamNewPipe#2611 and TeamNewPipe#8151
Browse files Browse the repository at this point in the history
  • Loading branch information
dtcxzyw committed Apr 19, 2022
1 parent 53bf342 commit cf1e532
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,18 +245,16 @@ public Builder setAction(@NonNull final StreamDialogDefaultEntry entry,
}

/**
* Adds {@link StreamDialogDefaultEntry#ENQUEUE} if the player is open and
* Adds {@link StreamDialogDefaultEntry#ENQUEUE} unconditionally and
* {@link StreamDialogDefaultEntry#ENQUEUE_NEXT} if there are multiple streams
* in the play queue.
* @return the current {@link Builder} instance
*/
public Builder addEnqueueEntriesIfNeeded() {
if (PlayerHolder.getInstance().isPlayQueueReady()) {
addEntry(StreamDialogDefaultEntry.ENQUEUE);
addEntry(StreamDialogDefaultEntry.ENQUEUE);

if (PlayerHolder.getInstance().getQueueSize() > 1) {
addEntry(StreamDialogDefaultEntry.ENQUEUE_NEXT);
}
if (PlayerHolder.getInstance().getQueueSize() > 1) {
addEntry(StreamDialogDefaultEntry.ENQUEUE_NEXT);
}
return this;
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/org/schabi/newpipe/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,11 @@ private void initPlayback(@NonNull final PlayQueue queue,

simpleExoPlayer.setVolume(isMuted ? 0 : 1);
notifyQueueUpdateToListeners();

// Buffer paused streams when users add streams to the play queue.
if (!playOnReady && !playQueue.isEmpty()) {
simpleExoPlayer.prepare();
}
}
//endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public boolean isBound() {
}

public int getQueueSize() {
if (player == null || player.getPlayQueue() == null) {
if (!isPlayQueueReady()) {
// player play queue might be null e.g. while player is starting
return 0;
}
Expand Down
11 changes: 9 additions & 2 deletions app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,14 @@ public static <T> Intent getPlayerEnqueueIntent(@NonNull final Context context,
// - if there is nothing already playing, it is useful for the enqueue action to have a
// 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
// by long pressing the video detail fragment, playlist or channel controls
return getPlayerIntent(context, targetClazz, playQueue, false)
// by long pressing the feed fragment, video detail fragment, playlist or channel
// controls)
final boolean resumePlayback = false;
// `playWhenReady` is false if the play queue is empty.
// Users may start playing manually after queuing up a bunch of videos.
// For more details, please see #2611 and #8151.
final boolean playWhenReady = PlayerHolder.getInstance().getQueueSize() > 0;
return getPlayerIntent(context, targetClazz, playQueue, resumePlayback, playWhenReady)
.putExtra(Player.ENQUEUE, true);
}

Expand Down Expand Up @@ -524,6 +530,7 @@ public static void openVideoDetail(final Context context,
* Opens {@link ChannelFragment}.
* Use this instead of {@link #openChannelFragment(FragmentManager, int, String, String)}
* when no fragments are used / no FragmentManager is available.
*
* @param context
* @param serviceId
* @param url
Expand Down

0 comments on commit cf1e532

Please sign in to comment.