use of org.robolectric.shadows.ShadowMediaPlayer.MediaEvent in project robolectric by robolectric.
the class ShadowMediaPlayerTest method testSimulatenousEventsAllRun.
@Test
public void testSimulatenousEventsAllRun() {
// Simultaneous events should all run even if
// one of them stops playback.
MediaEvent e1 = new MediaEvent() {
@Override
public void run(MediaPlayer mp, ShadowMediaPlayer smp) {
smp.doStop();
}
};
MediaEvent e2 = Mockito.mock(MediaEvent.class);
info.scheduleEventAtOffset(100, e1);
info.scheduleEventAtOffset(100, e2);
shadowMediaPlayer.setState(INITIALIZED);
shadowMediaPlayer.doStart();
scheduler.advanceBy(100);
// Verify that the first event ran
assertThat(shadowMediaPlayer.isReallyPlaying()).isFalse();
Mockito.verify(e2).run(mediaPlayer, shadowMediaPlayer);
}
use of org.robolectric.shadows.ShadowMediaPlayer.MediaEvent in project robolectric by robolectric.
the class ShadowMediaPlayerTest method testResetCancelsCallbacks.
@Test
public void testResetCancelsCallbacks() {
shadowMediaPlayer.setState(STARTED);
mediaPlayer.seekTo(100);
MediaEvent e = Mockito.mock(MediaEvent.class);
shadowMediaPlayer.postEventDelayed(e, 200);
mediaPlayer.reset();
assertThat(scheduler.size()).isEqualTo(0);
}
use of org.robolectric.shadows.ShadowMediaPlayer.MediaEvent in project robolectric by robolectric.
the class ShadowMediaPlayerTest method testRemoveEventAtOffset.
@Test
public void testRemoveEventAtOffset() {
shadowMediaPlayer.setState(PREPARED);
mediaPlayer.start();
scheduler.advanceBy(200);
MediaEvent e = info.scheduleInfoAtOffset(500, 1, 3);
scheduler.advanceBy(299);
info.removeEventAtOffset(500, e);
scheduler.advanceToLastPostedRunnable();
Mockito.verifyZeroInteractions(infoListener);
}
use of org.robolectric.shadows.ShadowMediaPlayer.MediaEvent in project robolectric by robolectric.
the class ShadowMediaPlayerTest method testReleaseCancelsSeekCallback.
@Test
public void testReleaseCancelsSeekCallback() {
shadowMediaPlayer.setState(STARTED);
mediaPlayer.seekTo(100);
MediaEvent e = Mockito.mock(MediaEvent.class);
shadowMediaPlayer.postEventDelayed(e, 200);
mediaPlayer.release();
assertThat(scheduler.size()).isEqualTo(0);
}
use of org.robolectric.shadows.ShadowMediaPlayer.MediaEvent in project robolectric by robolectric.
the class ShadowMediaPlayerTest method testScheduleMultipleRunnables.
@Test
public void testScheduleMultipleRunnables() {
shadowMediaPlayer.setState(PREPARED);
scheduler.advanceBy(25);
mediaPlayer.start();
scheduler.advanceBy(200);
assertThat(scheduler.size()).isEqualTo(1);
shadowMediaPlayer.doStop();
info.scheduleInfoAtOffset(250, 2, 4);
shadowMediaPlayer.doStart();
assertThat(scheduler.size()).isEqualTo(1);
MediaEvent e1 = Mockito.mock(MediaEvent.class);
shadowMediaPlayer.doStop();
info.scheduleEventAtOffset(400, e1);
shadowMediaPlayer.doStart();
scheduler.advanceBy(49);
Mockito.verifyZeroInteractions(infoListener);
scheduler.advanceBy(1);
Mockito.verify(infoListener).onInfo(mediaPlayer, 2, 4);
scheduler.advanceBy(149);
shadowMediaPlayer.doStop();
info.scheduleErrorAtOffset(675, 32, 22);
shadowMediaPlayer.doStart();
Mockito.verifyZeroInteractions(e1);
scheduler.advanceBy(1);
Mockito.verify(e1).run(mediaPlayer, shadowMediaPlayer);
mediaPlayer.pause();
assertThat(scheduler.size()).isEqualTo(0);
scheduler.advanceBy(324);
MediaEvent e2 = Mockito.mock(MediaEvent.class);
info.scheduleEventAtOffset(680, e2);
mediaPlayer.start();
scheduler.advanceBy(274);
Mockito.verifyZeroInteractions(errorListener);
scheduler.advanceBy(1);
Mockito.verify(errorListener).onError(mediaPlayer, 32, 22);
assertThat(scheduler.size()).isEqualTo(0);
assertThat(shadowMediaPlayer.getCurrentPositionRaw()).isEqualTo(675);
assertThat(shadowMediaPlayer.getState()).isSameAs(ERROR);
Mockito.verifyZeroInteractions(e2);
}
Aggregations