Search in sources :

Example 1 with STATE_ENDED

use of com.google.android.exoplayer2.Player.STATE_ENDED in project ExoPlayer by google.

the class ExoPlayerTest method onPlayerErrorChanged_isNotifiedForNullError.

@Test
public void onPlayerErrorChanged_isNotifiedForNullError() throws Exception {
    ExoPlayer player = new TestExoPlayerBuilder(context).build();
    player.addMediaSource(new FakeMediaSource(/* timeline= */
    null) {

        @Override
        public void maybeThrowSourceInfoRefreshError() throws IOException {
            throw new IOException();
        }
    });
    Player.Listener mockListener = mock(Player.Listener.class);
    player.addListener(mockListener);
    player.prepare();
    player.play();
    ExoPlaybackException error = TestPlayerRunHelper.runUntilError(player);
    // The media source fails preparation, so we expect both methods to be called.
    verify(mockListener).onPlayerErrorChanged(error);
    verify(mockListener).onPlayerError(error);
    reset(mockListener);
    player.setMediaSource(new FakeMediaSource());
    player.prepare();
    player.play();
    TestPlayerRunHelper.runUntilPlaybackState(player, STATE_ENDED);
    // Now the player, which had a playback error, was re-prepared causing the error to be cleared.
    // We expect the change to null to be notified, but not onPlayerError.
    verify(mockListener).onPlayerErrorChanged(ArgumentMatchers.isNull());
    verify(mockListener, never()).onPlayerError(any());
}
Also used : Listener(com.google.android.exoplayer2.Player.Listener) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) IOException(java.io.IOException) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Test(org.junit.Test)

Aggregations

Listener (com.google.android.exoplayer2.Player.Listener)1 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)1 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)1 IOException (java.io.IOException)1 Test (org.junit.Test)1