From d14f559e942792b007f81f8e1bf60cb39279850f Mon Sep 17 00:00:00 2001 From: tonihei Date: Thu, 30 Apr 2020 15:01:44 +0100 Subject: [PATCH] Fix message indexing bug. We keep an index hint for the next pending player message. This hint wasn't updated correctly when messages are removed due to a timeline update. This change makes sure to only use the hint locally in one method so that it doesn't need to be updated anywhere else and also adds the "hint" suffix to the variable name to make it clearer that it's just a hint and there are no guarantees this index actually exists anymore. issue:#7278 PiperOrigin-RevId: 309217614 --- RELEASENOTES.md | 6 +++++- .../google/android/exoplayer2/ExoPlayerImplInternal.java | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index a645a177135..697c78265f0 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -5,7 +5,11 @@ * Add `SilenceMediaSource.Factory` to support tags. * Enable the configuration of `SilenceSkippingAudioProcessor` ([#6705](https://github.com/google/ExoPlayer/issues/6705)). -* DownloadService: Fix "Not allowed to start service" `IllegalStateException` +* Fix bug where `PlayerMessages` throw an exception after `MediaSources` + are removed from the playlist + ([#7278](https://github.com/google/ExoPlayer/issues/7278)). +* Fix "Not allowed to start service" `IllegalStateException` in + `DownloadService` ([#7306](https://github.com/google/ExoPlayer/issues/7306)). * Ads: * Fix `AdsMediaSource` child `MediaSource`s not being released. diff --git a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java index 108d94abb43..ddc54e9e6ed 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java @@ -120,7 +120,7 @@ private int pendingPrepareCount; private SeekPosition pendingInitialSeekPosition; private long rendererPositionUs; - private int nextPendingMessageIndex; + private int nextPendingMessageIndexHint; private boolean deliverPendingMessageAtStartPositionRequired; public ExoPlayerImplInternal( @@ -928,7 +928,6 @@ private void resetInternal( pendingMessageInfo.message.markAsProcessed(/* isDelivered= */ false); } pendingMessages.clear(); - nextPendingMessageIndex = 0; } MediaPeriodId mediaPeriodId = resetPosition @@ -1082,6 +1081,7 @@ private void maybeTriggerPendingMessages(long oldPeriodPositionUs, long newPerio // Correct next index if necessary (e.g. after seeking, timeline changes, or new messages) int currentPeriodIndex = playbackInfo.timeline.getIndexOfPeriod(playbackInfo.periodId.periodUid); + int nextPendingMessageIndex = Math.min(nextPendingMessageIndexHint, pendingMessages.size()); PendingMessageInfo previousInfo = nextPendingMessageIndex > 0 ? pendingMessages.get(nextPendingMessageIndex - 1) : null; while (previousInfo != null @@ -1127,6 +1127,7 @@ private void maybeTriggerPendingMessages(long oldPeriodPositionUs, long newPerio ? pendingMessages.get(nextPendingMessageIndex) : null; } + nextPendingMessageIndexHint = nextPendingMessageIndex; } private void ensureStopped(Renderer renderer) throws ExoPlaybackException {