Skip to content

Commit e749075

Browse files
authored
Merge pull request #13195 from absurdlylongusername/fix-13139-resume-playback
Fix 13139 resume playback
2 parents 83f9646 + 1554f77 commit e749075

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

app/src/main/java/org/schabi/newpipe/player/Player.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -567,11 +567,7 @@ private static PlayQueue getPlayQueueFromCache(@NonNull final Intent intent) {
567567
if (queueCache == null) {
568568
return null;
569569
}
570-
final PlayQueue newQueue = SerializedCache.getInstance().take(queueCache, PlayQueue.class);
571-
if (newQueue == null) {
572-
return null;
573-
}
574-
return newQueue;
570+
return SerializedCache.getInstance().take(queueCache, PlayQueue.class);
575571
}
576572

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

22152211
isAudioOnly = !videoAndSubtitlesEnabled;
22162212

2213+
final var item = playQueue.getItem();
2214+
final boolean hasPendingRecovery =
2215+
item != null && item.getRecoveryPosition() != PlayQueueItem.RECOVERY_UNSET;
2216+
final boolean hasTimeline =
2217+
!exoPlayerIsNull() && !simpleExoPlayer.getCurrentTimeline().isEmpty();
2218+
2219+
22172220
getCurrentStreamInfo().ifPresentOrElse(info -> {
22182221
// In case we don't know the source type, fall back to either video-with-audio, or
22192222
// audio-only source type
22202223
final SourceType sourceType = videoResolver.getStreamSourceType()
22212224
.orElse(SourceType.VIDEO_WITH_AUDIO_OR_AUDIO_ONLY);
22222225

2223-
setRecovery(); // making sure to save playback position before reloadPlayQueueManager()
2226+
if (hasTimeline || !hasPendingRecovery) {
2227+
// making sure to save playback position before reloadPlayQueueManager()
2228+
setRecovery();
2229+
}
22242230

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

0 commit comments

Comments
 (0)