From f9055396b80e284bfa49687c2df7b952218bc37a Mon Sep 17 00:00:00 2001 From: andrewlewis Date: Fri, 15 Mar 2019 01:04:55 +0000 Subject: [PATCH] Post errors before calling stopInternal When an error occurs we call stopInternal, and this clears the MediaPeriodQueue, which in turn releases media period holders and notifies that media periods have been released. AnalyticsCollector updates its information about media periods using the media period release events, which means that if we post the source error after stopInternal posts its events we can't determine what media period the source error corresponds to. Move error notifications before calling stopInternal, so that AnalyticsCollector's model of the media period queue contains the loading period at the point when it handles the error. For consistency also move the other (non-source) error notifications to match the new ordering. PiperOrigin-RevId: 238559324 --- .../android/exoplayer2/ExoPlayerImplInternal.java | 12 ++++++------ .../exoplayer2/analytics/AnalyticsCollectorTest.java | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) 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 9dbe8f2e90..e61c689233 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 @@ -375,31 +375,31 @@ import java.util.concurrent.atomic.AtomicBoolean; maybeNotifyPlaybackInfoChanged(); } catch (ExoPlaybackException e) { Log.e(TAG, "Playback error.", e); + eventHandler.obtainMessage(MSG_ERROR, e).sendToTarget(); stopInternal( /* forceResetRenderers= */ true, /* resetPositionAndState= */ false, /* acknowledgeStop= */ false); - eventHandler.obtainMessage(MSG_ERROR, e).sendToTarget(); maybeNotifyPlaybackInfoChanged(); } catch (IOException e) { Log.e(TAG, "Source error.", e); + eventHandler.obtainMessage(MSG_ERROR, ExoPlaybackException.createForSource(e)).sendToTarget(); stopInternal( /* forceResetRenderers= */ false, /* resetPositionAndState= */ false, /* acknowledgeStop= */ false); - eventHandler.obtainMessage(MSG_ERROR, ExoPlaybackException.createForSource(e)).sendToTarget(); maybeNotifyPlaybackInfoChanged(); } catch (RuntimeException | OutOfMemoryError e) { Log.e(TAG, "Internal runtime error.", e); - stopInternal( - /* forceResetRenderers= */ true, - /* resetPositionAndState= */ false, - /* acknowledgeStop= */ false); ExoPlaybackException error = e instanceof OutOfMemoryError ? ExoPlaybackException.createForOutOfMemoryError((OutOfMemoryError) e) : ExoPlaybackException.createForUnexpected((RuntimeException) e); eventHandler.obtainMessage(MSG_ERROR, error).sendToTarget(); + stopInternal( + /* forceResetRenderers= */ true, + /* resetPositionAndState= */ false, + /* acknowledgeStop= */ false); maybeNotifyPlaybackInfoChanged(); } return true; diff --git a/library/core/src/test/java/com/google/android/exoplayer2/analytics/AnalyticsCollectorTest.java b/library/core/src/test/java/com/google/android/exoplayer2/analytics/AnalyticsCollectorTest.java index 5f307d3a88..af9591d1b7 100644 --- a/library/core/src/test/java/com/google/android/exoplayer2/analytics/AnalyticsCollectorTest.java +++ b/library/core/src/test/java/com/google/android/exoplayer2/analytics/AnalyticsCollectorTest.java @@ -533,7 +533,7 @@ public final class AnalyticsCollectorTest { .containsExactly(WINDOW_0 /* prepared */, WINDOW_0 /* prepared */); assertThat(listener.getEvents(EVENT_LOADING_CHANGED)) .containsExactly(period0Seq0, period0Seq0, period0Seq0, period0Seq0); - assertThat(listener.getEvents(EVENT_PLAYER_ERROR)).containsExactly(WINDOW_0); + assertThat(listener.getEvents(EVENT_PLAYER_ERROR)).containsExactly(period0Seq0); assertThat(listener.getEvents(EVENT_TRACKS_CHANGED)).containsExactly(period0Seq0, period0Seq0); assertThat(listener.getEvents(EVENT_LOAD_STARTED)) .containsExactly(