diff --git a/app/src/main/java/org/schabi/newpipe/player/Player.java b/app/src/main/java/org/schabi/newpipe/player/Player.java index e18ead89992..b07b15a4585 100644 --- a/app/src/main/java/org/schabi/newpipe/player/Player.java +++ b/app/src/main/java/org/schabi/newpipe/player/Player.java @@ -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() { @@ -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); } @@ -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(); @@ -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(); });