Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions app/src/main/java/org/schabi/newpipe/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -567,11 +567,7 @@ private static PlayQueue getPlayQueueFromCache(@NonNull final Intent intent) {
if (queueCache == null) {
return null;
}
final PlayQueue newQueue = SerializedCache.getInstance().take(queueCache, PlayQueue.class);
if (newQueue == null) {
return null;
}
return newQueue;
return SerializedCache.getInstance().take(queueCache, PlayQueue.class);
}

private void initUIsForCurrentPlayerType() {
Expand Down Expand Up @@ -2041,7 +2037,7 @@ public MediaSource sourceOf(final PlayQueueItem item, final StreamInfo info) {
// resolver was called when the app was in background, the app will only stream audio when
// the user come back to the app and will never fetch the video stream.
// Note that the video is not fetched when the app is in background because the video
// renderer is fully disabled (see useVideoSource method), except for HLS streams
// renderer is fully disabled (see useVideoAndSubtitles method), except for HLS streams
// (see https://github.com/google/ExoPlayer/issues/9282).
return videoResolver.resolve(info);
}
Expand Down Expand Up @@ -2214,13 +2210,23 @@ public void useVideoAndSubtitles(final boolean videoAndSubtitlesEnabled) {

isAudioOnly = !videoAndSubtitlesEnabled;

final var item = playQueue.getItem();
final boolean hasPendingRecovery =
item != null && item.getRecoveryPosition() != PlayQueueItem.RECOVERY_UNSET;
final boolean hasTimeline =
!exoPlayerIsNull() && !simpleExoPlayer.getCurrentTimeline().isEmpty();


getCurrentStreamInfo().ifPresentOrElse(info -> {
// In case we don't know the source type, fall back to either video-with-audio, or
// audio-only source type
final SourceType sourceType = videoResolver.getStreamSourceType()
.orElse(SourceType.VIDEO_WITH_AUDIO_OR_AUDIO_ONLY);

setRecovery(); // making sure to save playback position before reloadPlayQueueManager()
if (hasTimeline || !hasPendingRecovery) {
// making sure to save playback position before reloadPlayQueueManager()
setRecovery();
}

if (playQueueManagerReloadingNeeded(sourceType, info, getVideoRendererIndex())) {
reloadPlayQueueManager();
Expand All @@ -2233,7 +2239,10 @@ The current metadata may be null sometimes (for e.g. when using an unstable conn
Reload the play queue manager in this case, which is the behavior when we don't know the
index of the video renderer or playQueueManagerReloadingNeeded returns true
*/
setRecovery(); // making sure to save playback position before reloadPlayQueueManager()
if (hasTimeline || !hasPendingRecovery) {
// making sure to save playback position before reloadPlayQueueManager()
setRecovery();
}
reloadPlayQueueManager();
});

Expand Down
Loading