Search in sources :

Example 26 with Clip

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

the class SelectOneWidgetTest method whenChoicesHaveAudio_audioButtonUsesIndexAsClipID.

@Test
public void whenChoicesHaveAudio_audioButtonUsesIndexAsClipID() throws Exception {
    formEntryPrompt = new MockFormEntryPromptBuilder().withIndex("i am index").withSelectChoices(asList(new SelectChoice("1", "1"), new SelectChoice("2", "2"))).withSpecialFormSelectChoiceText(asList(new Pair<>(FormEntryCaption.TEXT_FORM_AUDIO, REFERENCES.get(0).first), new Pair<>(FormEntryCaption.TEXT_FORM_AUDIO, REFERENCES.get(1).first))).build();
    populateRecyclerView(getWidget());
    verify(audioHelper).setAudio(any(AudioButton.class), eq(new Clip("i am index 0", REFERENCES.get(0).second)));
    verify(audioHelper).setAudio(any(AudioButton.class), eq(new Clip("i am index 1", REFERENCES.get(1).second)));
}
Also used : Clip(org.odk.collect.audioclips.Clip) SelectChoice(org.javarosa.core.model.SelectChoice) MockFormEntryPromptBuilder(org.odk.collect.android.support.MockFormEntryPromptBuilder) AudioButton(org.odk.collect.android.audio.AudioButton) Pair(androidx.core.util.Pair) GeneralSelectOneWidgetTest(org.odk.collect.android.widgets.base.GeneralSelectOneWidgetTest) Test(org.junit.Test)

Example 27 with Clip

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

the class ExAudioWidget method updatePlayerMedia.

private void updatePlayerMedia() {
    if (answerFile != null) {
        Clip clip = new Clip("audio:" + getFormEntryPrompt().getIndex().toString(), answerFile.getAbsolutePath());
        audioPlayer.onPlayingChanged(clip.getClipID(), binding.audioPlayer.audioController::setPlaying);
        audioPlayer.onPositionChanged(clip.getClipID(), binding.audioPlayer.audioController::setPosition);
        binding.audioPlayer.audioController.setDuration(getDurationOfFile(clip.getURI()));
        binding.audioPlayer.audioController.setListener(new AudioControllerView.Listener() {

            @Override
            public void onPlayClicked() {
                audioPlayer.play(clip);
            }

            @Override
            public void onPauseClicked() {
                audioPlayer.pause();
            }

            @Override
            public void onPositionChanged(Integer newPosition) {
                AnalyticsUtils.logFormEvent(AnalyticsEvents.AUDIO_PLAYER_SEEK);
                audioPlayer.setPosition(clip.getClipID(), newPosition);
            }

            @Override
            public void onRemoveClicked() {
                new MaterialAlertDialogBuilder(getContext()).setTitle(R.string.delete_answer_file_question).setMessage(R.string.answer_file_delete_warning).setPositiveButton(R.string.delete_answer_file, (dialog, which) -> clearAnswer()).setNegativeButton(R.string.cancel, null).show();
            }
        });
    }
}
Also used : Clip(org.odk.collect.audioclips.Clip) Context(android.content.Context) AudioPlayer(org.odk.collect.android.widgets.utilities.AudioPlayer) MediaMetadataRetriever(android.media.MediaMetadataRetriever) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) FileWidget(org.odk.collect.android.widgets.interfaces.FileWidget) ApplicationConstants(org.odk.collect.android.utilities.ApplicationConstants) FileUtils(org.odk.collect.android.utilities.FileUtils) SuppressLint(android.annotation.SuppressLint) AnalyticsUtils(org.odk.collect.android.analytics.AnalyticsUtils) ExAudioWidgetAnswerBinding(org.odk.collect.android.databinding.ExAudioWidgetAnswerBinding) FileRequester(org.odk.collect.android.widgets.utilities.FileRequester) WaitingForDataRegistry(org.odk.collect.android.widgets.utilities.WaitingForDataRegistry) ToastUtils(org.odk.collect.androidshared.ui.ToastUtils) IAnswerData(org.javarosa.core.model.data.IAnswerData) R(org.odk.collect.android.R) View(android.view.View) QuestionDetails(org.odk.collect.android.formentry.questions.QuestionDetails) AudioControllerView(org.odk.collect.android.audio.AudioControllerView) FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) Clip(org.odk.collect.audioclips.Clip) StringData(org.javarosa.core.model.data.StringData) QuestionMediaManager(org.odk.collect.android.utilities.QuestionMediaManager) AnalyticsEvents(org.odk.collect.android.analytics.AnalyticsEvents) WidgetDataReceiver(org.odk.collect.android.widgets.interfaces.WidgetDataReceiver) File(java.io.File) Timber(timber.log.Timber) TypedValue(android.util.TypedValue) Activity(android.app.Activity) AudioControllerView(org.odk.collect.android.audio.AudioControllerView) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder)

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