Commit f9055396 by andrewlewis Committed by Oliver Woodman

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
parent d088be7a
...@@ -375,31 +375,31 @@ import java.util.concurrent.atomic.AtomicBoolean; ...@@ -375,31 +375,31 @@ import java.util.concurrent.atomic.AtomicBoolean;
maybeNotifyPlaybackInfoChanged(); maybeNotifyPlaybackInfoChanged();
} catch (ExoPlaybackException e) { } catch (ExoPlaybackException e) {
Log.e(TAG, "Playback error.", e); Log.e(TAG, "Playback error.", e);
eventHandler.obtainMessage(MSG_ERROR, e).sendToTarget();
stopInternal( stopInternal(
/* forceResetRenderers= */ true, /* forceResetRenderers= */ true,
/* resetPositionAndState= */ false, /* resetPositionAndState= */ false,
/* acknowledgeStop= */ false); /* acknowledgeStop= */ false);
eventHandler.obtainMessage(MSG_ERROR, e).sendToTarget();
maybeNotifyPlaybackInfoChanged(); maybeNotifyPlaybackInfoChanged();
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "Source error.", e); Log.e(TAG, "Source error.", e);
eventHandler.obtainMessage(MSG_ERROR, ExoPlaybackException.createForSource(e)).sendToTarget();
stopInternal( stopInternal(
/* forceResetRenderers= */ false, /* forceResetRenderers= */ false,
/* resetPositionAndState= */ false, /* resetPositionAndState= */ false,
/* acknowledgeStop= */ false); /* acknowledgeStop= */ false);
eventHandler.obtainMessage(MSG_ERROR, ExoPlaybackException.createForSource(e)).sendToTarget();
maybeNotifyPlaybackInfoChanged(); maybeNotifyPlaybackInfoChanged();
} catch (RuntimeException | OutOfMemoryError e) { } catch (RuntimeException | OutOfMemoryError e) {
Log.e(TAG, "Internal runtime error.", e); Log.e(TAG, "Internal runtime error.", e);
stopInternal(
/* forceResetRenderers= */ true,
/* resetPositionAndState= */ false,
/* acknowledgeStop= */ false);
ExoPlaybackException error = ExoPlaybackException error =
e instanceof OutOfMemoryError e instanceof OutOfMemoryError
? ExoPlaybackException.createForOutOfMemoryError((OutOfMemoryError) e) ? ExoPlaybackException.createForOutOfMemoryError((OutOfMemoryError) e)
: ExoPlaybackException.createForUnexpected((RuntimeException) e); : ExoPlaybackException.createForUnexpected((RuntimeException) e);
eventHandler.obtainMessage(MSG_ERROR, error).sendToTarget(); eventHandler.obtainMessage(MSG_ERROR, error).sendToTarget();
stopInternal(
/* forceResetRenderers= */ true,
/* resetPositionAndState= */ false,
/* acknowledgeStop= */ false);
maybeNotifyPlaybackInfoChanged(); maybeNotifyPlaybackInfoChanged();
} }
return true; return true;
......
...@@ -533,7 +533,7 @@ public final class AnalyticsCollectorTest { ...@@ -533,7 +533,7 @@ public final class AnalyticsCollectorTest {
.containsExactly(WINDOW_0 /* prepared */, WINDOW_0 /* prepared */); .containsExactly(WINDOW_0 /* prepared */, WINDOW_0 /* prepared */);
assertThat(listener.getEvents(EVENT_LOADING_CHANGED)) assertThat(listener.getEvents(EVENT_LOADING_CHANGED))
.containsExactly(period0Seq0, period0Seq0, period0Seq0, period0Seq0); .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_TRACKS_CHANGED)).containsExactly(period0Seq0, period0Seq0);
assertThat(listener.getEvents(EVENT_LOAD_STARTED)) assertThat(listener.getEvents(EVENT_LOAD_STARTED))
.containsExactly( .containsExactly(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment