Search in sources :

Example 1 with MediaInfo

use of org.robolectric.shadows.ShadowMediaPlayer.MediaInfo in project robolectric by robolectric.

the class ShadowMediaPlayerTest method testSetDataSourceUsesCustomMediaInfoProvider.

@Test
public void testSetDataSourceUsesCustomMediaInfoProvider() throws Exception {
    MediaInfo mediaInfo = new MediaInfo();
    ShadowMediaPlayer.setMediaInfoProvider(unused -> mediaInfo);
    String path = "data_source_path";
    DataSource ds = toDataSource(path);
    mediaPlayer.setDataSource(path);
    assertWithMessage("dataSource").that(shadowMediaPlayer.getDataSource()).isEqualTo(ds);
    assertWithMessage("mediaInfo").that(shadowMediaPlayer.getMediaInfo()).isSameInstanceAs(mediaInfo);
}
Also used : MediaInfo(org.robolectric.shadows.ShadowMediaPlayer.MediaInfo) DataSource(org.robolectric.shadows.util.DataSource) MediaDataSource(android.media.MediaDataSource) DataSource.toDataSource(org.robolectric.shadows.util.DataSource.toDataSource) Test(org.junit.Test)

Example 2 with MediaInfo

use of org.robolectric.shadows.ShadowMediaPlayer.MediaInfo in project robolectric by robolectric.

the class ShadowMediaPlayerTest method setUp.

@Before
public void setUp() {
    mediaPlayer = Shadow.newInstanceOf(MediaPlayer.class);
    shadowMediaPlayer = shadowOf(mediaPlayer);
    completionListener = Mockito.mock(MediaPlayer.OnCompletionListener.class);
    mediaPlayer.setOnCompletionListener(completionListener);
    preparedListener = Mockito.mock(MediaPlayer.OnPreparedListener.class);
    mediaPlayer.setOnPreparedListener(preparedListener);
    errorListener = Mockito.mock(MediaPlayer.OnErrorListener.class);
    mediaPlayer.setOnErrorListener(errorListener);
    infoListener = Mockito.mock(MediaPlayer.OnInfoListener.class);
    mediaPlayer.setOnInfoListener(infoListener);
    seekListener = Mockito.mock(MediaPlayer.OnSeekCompleteListener.class);
    mediaPlayer.setOnSeekCompleteListener(seekListener);
    shadowMainLooper().pause();
    defaultSource = toDataSource(DUMMY_SOURCE);
    info = new MediaInfo();
    ShadowMediaPlayer.addMediaInfo(defaultSource, info);
    shadowMediaPlayer.doSetDataSource(defaultSource);
}
Also used : MediaInfo(org.robolectric.shadows.ShadowMediaPlayer.MediaInfo) MediaPlayer(android.media.MediaPlayer) Before(org.junit.Before)

Aggregations

MediaInfo (org.robolectric.shadows.ShadowMediaPlayer.MediaInfo)2 MediaDataSource (android.media.MediaDataSource)1 MediaPlayer (android.media.MediaPlayer)1 Before (org.junit.Before)1 Test (org.junit.Test)1 DataSource (org.robolectric.shadows.util.DataSource)1 DataSource.toDataSource (org.robolectric.shadows.util.DataSource.toDataSource)1