Search in sources :

Example 1 with DataSource

use of org.robolectric.shadows.util.DataSource in project robolectric by robolectric.

the class ShadowMediaPlayerTest method testSetDataSourceUri.

@Test
public void testSetDataSourceUri() throws IOException {
    Map<String, String> headers = new HashMap<>();
    Uri uri = Uri.parse("file:/test");
    DataSource ds = toDataSource(RuntimeEnvironment.application, uri, headers);
    ShadowMediaPlayer.addMediaInfo(ds, info);
    mediaPlayer.setDataSource(RuntimeEnvironment.application, uri, headers);
    assertThat(shadowMediaPlayer.getSourceUri()).as("sourceUri").isSameAs(uri);
    assertThat(shadowMediaPlayer.getDataSource()).as("dataSource").isEqualTo(ds);
}
Also used : HashMap(java.util.HashMap) Uri(android.net.Uri) DataSource(org.robolectric.shadows.util.DataSource) DataSource.toDataSource(org.robolectric.shadows.util.DataSource.toDataSource) Test(org.junit.Test)

Example 2 with DataSource

use of org.robolectric.shadows.util.DataSource in project robolectric by robolectric.

the class ShadowMediaPlayerTest method testSetDataSourceAssetFileDescriptorDataSource.

@Config(minSdk = N)
@Test
public void testSetDataSourceAssetFileDescriptorDataSource() throws IOException {
    Application context = ApplicationProvider.getApplicationContext();
    try (AssetFileDescriptor fd = context.getResources().openRawResourceFd(R.drawable.an_image)) {
        DataSource ds = toDataSource(fd);
        ShadowMediaPlayer.addMediaInfo(ds, info);
        mediaPlayer.setDataSource(fd);
        assertWithMessage("dataSource").that(shadowMediaPlayer.getDataSource()).isEqualTo(ds);
    }
}
Also used : AssetFileDescriptor(android.content.res.AssetFileDescriptor) Application(android.app.Application) DataSource(org.robolectric.shadows.util.DataSource) MediaDataSource(android.media.MediaDataSource) DataSource.toDataSource(org.robolectric.shadows.util.DataSource.toDataSource) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 3 with DataSource

use of org.robolectric.shadows.util.DataSource 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 4 with DataSource

use of org.robolectric.shadows.util.DataSource in project robolectric by robolectric.

the class ShadowMediaPlayerTest method testSetDataSourceMediaDataSource.

@Config(minSdk = M)
@Test
public void testSetDataSourceMediaDataSource() {
    MediaDataSource mediaDataSource = new MediaDataSource() {

        @Override
        public void close() {
        }

        @Override
        public int readAt(long position, byte[] buffer, int offset, int size) {
            return 0;
        }

        @Override
        public long getSize() {
            return 0;
        }
    };
    DataSource ds = toDataSource(mediaDataSource);
    ShadowMediaPlayer.addMediaInfo(ds, info);
    mediaPlayer.setDataSource(mediaDataSource);
    assertWithMessage("dataSource").that(shadowMediaPlayer.getDataSource()).isEqualTo(ds);
}
Also used : MediaDataSource(android.media.MediaDataSource) DataSource(org.robolectric.shadows.util.DataSource) MediaDataSource(android.media.MediaDataSource) DataSource.toDataSource(org.robolectric.shadows.util.DataSource.toDataSource) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 5 with DataSource

use of org.robolectric.shadows.util.DataSource in project robolectric by robolectric.

the class ShadowMediaPlayerTest method testSetDataSource_withUriAndHeaders.

@Test
public void testSetDataSource_withUriAndHeaders() throws IOException {
    Map<String, String> headers = new HashMap<>();
    Uri uri = Uri.parse("file:/test");
    DataSource ds = toDataSource(ApplicationProvider.getApplicationContext(), uri, headers);
    ShadowMediaPlayer.addMediaInfo(ds, info);
    mediaPlayer.setDataSource(ApplicationProvider.getApplicationContext(), uri, headers);
    assertWithMessage("sourceUri").that(shadowMediaPlayer.getSourceUri()).isSameInstanceAs(uri);
    assertWithMessage("dataSource").that(shadowMediaPlayer.getDataSource()).isEqualTo(ds);
}
Also used : HashMap(java.util.HashMap) Uri(android.net.Uri) DataSource(org.robolectric.shadows.util.DataSource) MediaDataSource(android.media.MediaDataSource) DataSource.toDataSource(org.robolectric.shadows.util.DataSource.toDataSource) Test(org.junit.Test)

Aggregations

DataSource (org.robolectric.shadows.util.DataSource)13 Test (org.junit.Test)12 DataSource.toDataSource (org.robolectric.shadows.util.DataSource.toDataSource)10 MediaDataSource (android.media.MediaDataSource)9 Uri (android.net.Uri)3 AssetFileDescriptor (android.content.res.AssetFileDescriptor)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Clip (org.odk.collect.audioclips.Clip)2 RobolectricHelpers.setupMediaPlayerDataSource (org.odk.collect.testshared.RobolectricHelpers.setupMediaPlayerDataSource)2 Config (org.robolectric.annotation.Config)2 Application (android.app.Application)1 MediaPlayer (android.media.MediaPlayer)1 File (java.io.File)1 FileDescriptor (java.io.FileDescriptor)1 FileInputStream (java.io.FileInputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ExecutionException (java.util.concurrent.ExecutionException)1 Implementation (org.robolectric.annotation.Implementation)1 ShadowMediaPlayer (org.robolectric.shadows.ShadowMediaPlayer)1