Search in sources :

Example 6 with Clip

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

the class PromptAutoplayerTest method whenPromptHasAutoplayAudio_andIsSelectOne_withNoButtonsAppearance_playsPromptAudio.

@Test
public void whenPromptHasAutoplayAudio_andIsSelectOne_withNoButtonsAppearance_playsPromptAudio() throws Exception {
    FormEntryPrompt prompt = new MockFormEntryPromptBuilder().withControlType(Constants.CONTROL_SELECT_ONE).withAppearance("whatever " + NO_BUTTONS).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)));
}
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 7 with Clip

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

the class PromptAutoplayerTest method whenPromptHasAutoplayAudio_andIsSelectOne_withDeprecatedCompactAppearance_playsPromptAudio.

@Test
public void whenPromptHasAutoplayAudio_andIsSelectOne_withDeprecatedCompactAppearance_playsPromptAudio() throws Exception {
    FormEntryPrompt prompt = new MockFormEntryPromptBuilder().withControlType(Constants.CONTROL_SELECT_ONE).withAppearance(COMPACT).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)));
}
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 8 with Clip

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

the class AudioWidgetTest method afterSetBinaryData_showsDurationOfAudio.

@Test
public void afterSetBinaryData_showsDurationOfAudio() throws Exception {
    FormEntryPrompt prompt = promptWithAnswer(null);
    File answerFile = questionMediaManager.addAnswerFile(File.createTempFile("blah", ".mp3"));
    Clip expectedClip = getExpectedClip(prompt, answerFile.getName());
    setupMediaPlayerDataSource(expectedClip.getURI(), 322450);
    AudioWidget widget = createWidget(prompt);
    widget.setData(answerFile);
    AudioControllerView audioController = widget.binding.audioPlayer.audioController;
    assertThat(audioController.binding.totalDuration.getText().toString(), is("05:22"));
}
Also used : Clip(org.odk.collect.audioclips.Clip) FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) AudioControllerView(org.odk.collect.android.audio.AudioControllerView) File(java.io.File) Test(org.junit.Test)

Example 9 with Clip

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

the class AudioWidgetTest method afterSetBinaryData_whenPositionOfClipChanges_updatesPosition.

@Test
public void afterSetBinaryData_whenPositionOfClipChanges_updatesPosition() throws Exception {
    FormEntryPrompt prompt = promptWithAnswer(null);
    File answerFile = questionMediaManager.addAnswerFile(File.createTempFile("blah", ".mp3"));
    Clip expectedClip = getExpectedClip(prompt, answerFile.getName());
    setupMediaPlayerDataSource(expectedClip.getURI(), 322450);
    AudioWidget widget = createWidget(prompt);
    widget.setData(answerFile);
    AudioControllerView audioController = widget.binding.audioPlayer.audioController;
    assertThat(audioController.binding.currentDuration.getText().toString(), is("00:00"));
    audioPlayer.setPosition(expectedClip.getClipID(), 42000);
    assertThat(audioController.binding.currentDuration.getText().toString(), is("00:42"));
}
Also used : Clip(org.odk.collect.audioclips.Clip) FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) AudioControllerView(org.odk.collect.android.audio.AudioControllerView) File(java.io.File) Test(org.junit.Test)

Example 10 with Clip

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

the class AudioWidgetTest method afterSetBinaryData_clickingPlayAndPause_playsAndPausesAudio.

@Test
public void afterSetBinaryData_clickingPlayAndPause_playsAndPausesAudio() throws Exception {
    FormEntryPrompt prompt = promptWithAnswer(null);
    AudioWidget widget = createWidget(prompt);
    File answerFile = questionMediaManager.addAnswerFile(File.createTempFile("blah", ".mp3"));
    Clip expectedClip = getExpectedClip(prompt, answerFile.getName());
    widget.setData(answerFile);
    AudioControllerView audioController = widget.binding.audioPlayer.audioController;
    assertThat(audioController.getVisibility(), is(VISIBLE));
    audioController.binding.play.performClick();
    assertThat(audioPlayer.getCurrentClip(), is(expectedClip));
    audioController.binding.play.performClick();
    assertThat(audioPlayer.getCurrentClip(), is(expectedClip));
    assertThat(audioPlayer.isPaused(), is(true));
    audioController.binding.play.performClick();
    assertThat(audioPlayer.getCurrentClip(), is(expectedClip));
    assertThat(audioPlayer.isPaused(), is(false));
}
Also used : Clip(org.odk.collect.audioclips.Clip) FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) AudioControllerView(org.odk.collect.android.audio.AudioControllerView) File(java.io.File) 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