Search in sources :

Example 11 with DataSource

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

the class AudioButtonIntegrationTest method canPlayAndStopAudio.

@Test
public void canPlayAndStopAudio() throws Exception {
    String testFile = File.createTempFile("audio", ".mp3").getAbsolutePath();
    final DataSource dataSource = setupMediaPlayerDataSource(testFile);
    AudioButton button = new AudioButton(activity);
    audioHelper.setAudio(button, new Clip("clip1", testFile));
    assertThat(button.isPlaying(), equalTo(false));
    button.performClick();
    assertThat(mediaPlayer.isPlaying(), is(true));
    assertThat(shadowOf(mediaPlayer).getDataSource(), equalTo(dataSource));
    assertThat(button.isPlaying(), equalTo(true));
    button.performClick();
    assertThat(mediaPlayer.isPlaying(), is(false));
    assertThat(button.isPlaying(), equalTo(false));
}
Also used : Clip(org.odk.collect.audioclips.Clip) RobolectricHelpers.setupMediaPlayerDataSource(org.odk.collect.testshared.RobolectricHelpers.setupMediaPlayerDataSource) DataSource(org.robolectric.shadows.util.DataSource) Test(org.junit.Test)

Example 12 with DataSource

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

the class AudioButtonIntegrationTest method playingAudio_stopsOtherAudio.

@Test
public void playingAudio_stopsOtherAudio() throws Exception {
    String testFile1 = File.createTempFile("audio1", ".mp3").getAbsolutePath();
    String testFile2 = File.createTempFile("audio2", ".mp3").getAbsolutePath();
    setupMediaPlayerDataSource(testFile1);
    final DataSource dataSource2 = setupMediaPlayerDataSource(testFile2);
    AudioButton button1 = new AudioButton(activity);
    audioHelper.setAudio(button1, new Clip("clip1", testFile1));
    AudioButton button2 = new AudioButton(activity);
    audioHelper.setAudio(button2, new Clip("clip2", testFile2));
    button1.performClick();
    button2.performClick();
    assertThat(mediaPlayer.isPlaying(), is(true));
    assertThat(shadowOf(mediaPlayer).getDataSource(), equalTo(dataSource2));
    assertThat(button2.isPlaying(), equalTo(true));
    assertThat(button1.isPlaying(), equalTo(false));
}
Also used : Clip(org.odk.collect.audioclips.Clip) RobolectricHelpers.setupMediaPlayerDataSource(org.odk.collect.testshared.RobolectricHelpers.setupMediaPlayerDataSource) DataSource(org.robolectric.shadows.util.DataSource) Test(org.junit.Test)

Example 13 with DataSource

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

the class ShadowSettingsMediaPlayer method create.

@Implementation
public static MediaPlayer create(Context context, Uri uri) {
    final DataSource ds = DataSource.toDataSource(context, uri);
    addMediaInfo(ds, new ShadowMediaPlayer.MediaInfo());
    final MediaPlayer mp = new MediaPlayer();
    final ShadowMediaPlayer shadow = Shadow.extract(mp);
    try {
        shadow.setDataSource(ds);
        shadow.setState(INITIALIZED);
        mp.prepare();
    } catch (Exception e) {
        return null;
    }
    return mp;
}
Also used : ShadowMediaPlayer(org.robolectric.shadows.ShadowMediaPlayer) DataSource(org.robolectric.shadows.util.DataSource) MediaPlayer(android.media.MediaPlayer) ShadowMediaPlayer(org.robolectric.shadows.ShadowMediaPlayer) Implementation(org.robolectric.annotation.Implementation)

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