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));
}
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));
}
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;
}
Aggregations