Search in sources :

Example 11 with Clip

use of org.odk.collect.audioclips.Clip in project collect by opendatakit.

the class PromptAutoplayerTest method whenPromptHasAutoplayAudio_andIsSelectOne_playsAudioInOrder.

@Test
public void whenPromptHasAutoplayAudio_andIsSelectOne_playsAudioInOrder() {
    FormEntryPrompt prompt = new MockFormEntryPromptBuilder().withControlType(Constants.CONTROL_SELECT_ONE).withAudioURI(REFERENCES.get(0).first).withAdditionalAttribute("autoplay", "audio").withSelectChoices(asList(new SelectChoice("1", "1"), new SelectChoice("2", "2"))).withSpecialFormSelectChoiceText(asList(new Pair<>(FormEntryCaption.TEXT_FORM_AUDIO, REFERENCES.get(1).first), new Pair<>(FormEntryCaption.TEXT_FORM_AUDIO, REFERENCES.get(2).first))).build();
    assertThat(autoplayer.autoplayIfNeeded(prompt), equalTo(true));
    verify(audioHelper).playInOrder(asList(new Clip(prompt.getIndex().toString(), REFERENCES.get(0).second), new Clip(prompt.getIndex().toString() + " 0", REFERENCES.get(1).second), new Clip(prompt.getIndex().toString() + " 1", REFERENCES.get(2).second)));
}
Also used : Clip(org.odk.collect.audioclips.Clip) FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) SelectChoice(org.javarosa.core.model.SelectChoice) MockFormEntryPromptBuilder(org.odk.collect.android.support.MockFormEntryPromptBuilder) Test(org.junit.Test)

Example 12 with Clip

use of org.odk.collect.audioclips.Clip in project collect by opendatakit.

the class PromptAutoplayerTest method whenPromptHasAutoplayAudio_andIsSelectOne_butNoSelectChoiceAudio_playsPromptAudio.

@Test
public void whenPromptHasAutoplayAudio_andIsSelectOne_butNoSelectChoiceAudio_playsPromptAudio() throws Exception {
    FormEntryPrompt prompt = new MockFormEntryPromptBuilder().withControlType(Constants.CONTROL_SELECT_ONE).withAudioURI(REFERENCES.get(0).first).withAdditionalAttribute("autoplay", "audio").withSelectChoices(asList(new SelectChoice("1", "1"), new SelectChoice("2", "2"))).build();
    assertThat(autoplayer.autoplayIfNeeded(prompt), equalTo(true));
    verify(audioHelper).playInOrder(asList(new Clip(prompt.getIndex().toString(), REFERENCES.get(0).second)));
}
Also used : Clip(org.odk.collect.audioclips.Clip) FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) SelectChoice(org.javarosa.core.model.SelectChoice) MockFormEntryPromptBuilder(org.odk.collect.android.support.MockFormEntryPromptBuilder) Test(org.junit.Test)

Example 13 with Clip

use of org.odk.collect.audioclips.Clip 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 14 with Clip

use of org.odk.collect.audioclips.Clip 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 15 with Clip

use of org.odk.collect.audioclips.Clip in project collect by opendatakit.

the class AudioButtonIntegrationTest method destroyingLifecycle_releaseMediaPlayer.

@Test
public void destroyingLifecycle_releaseMediaPlayer() throws Exception {
    String testFile1 = File.createTempFile("audio1", ".mp3").getAbsolutePath();
    setupMediaPlayerDataSource(testFile1);
    AudioButton button = new AudioButton(activity);
    audioHelper.setAudio(button, new Clip("clip1", testFile1));
    fakeLifecycleOwner.destroy();
    assertThat(shadowOf(mediaPlayer).getState(), equalTo(ShadowMediaPlayer.State.END));
}
Also used : Clip(org.odk.collect.audioclips.Clip) Test(org.junit.Test)

Aggregations

Clip (org.odk.collect.audioclips.Clip)27 Test (org.junit.Test)21 FormEntryPrompt (org.javarosa.form.api.FormEntryPrompt)15 MockFormEntryPromptBuilder (org.odk.collect.android.support.MockFormEntryPromptBuilder)12 SelectChoice (org.javarosa.core.model.SelectChoice)10 File (java.io.File)5 AudioControllerView (org.odk.collect.android.audio.AudioControllerView)5 AudioButton (org.odk.collect.android.audio.AudioButton)3 QuestionDetails (org.odk.collect.android.formentry.questions.QuestionDetails)3 SuppressLint (android.annotation.SuppressLint)2 Context (android.content.Context)2 MediaMetadataRetriever (android.media.MediaMetadataRetriever)2 TypedValue (android.util.TypedValue)2 View (android.view.View)2 Pair (androidx.core.util.Pair)2 MaterialAlertDialogBuilder (com.google.android.material.dialog.MaterialAlertDialogBuilder)2 ArrayList (java.util.ArrayList)2 IAnswerData (org.javarosa.core.model.data.IAnswerData)2 StringData (org.javarosa.core.model.data.StringData)2 R (org.odk.collect.android.R)2