Search in sources :

Example 1 with Clip

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

the class AbstractSelectListAdapter method playAudio.

public void playAudio(SelectChoice selectChoice) {
    audioHelper.stop();
    Clip clip = getClip(prompt, selectChoice, referenceManager);
    if (clip != null) {
        audioHelper.play(clip);
    }
}
Also used : FormMediaUtils.getClip(org.odk.collect.android.formentry.media.FormMediaUtils.getClip) Clip(org.odk.collect.audioclips.Clip)

Example 2 with Clip

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

the class AudioVideoImageTextLabel method setupAudioButton.

private void setupAudioButton(String audioURI, AudioHelper audioHelper) {
    binding.audioButton.setVisibility(VISIBLE);
    binding.mediaButtons.setVisibility(VISIBLE);
    ScreenContext activity = getScreenContext();
    String clipID = getTag() != null ? getTag().toString() : "";
    LiveData<Boolean> isPlayingLiveData = audioHelper.setAudio(binding.audioButton, new Clip(clipID, audioURI));
    originalTextColor = textLabel.getTextColors().getDefaultColor();
    isPlayingLiveData.observe(activity.getViewLifecycle(), isPlaying -> {
        if (isPlaying) {
            textLabel.setTextColor(playTextColor);
        } else {
            textLabel.setTextColor(originalTextColor);
            // then set the text to our original (brings back any html formatting)
            textLabel.setText(questionText);
        }
    });
}
Also used : Clip(org.odk.collect.audioclips.Clip) ScreenContext(org.odk.collect.android.utilities.ScreenContext)

Example 3 with Clip

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

the class PromptAutoplayer method autoplayIfNeeded.

public Boolean autoplayIfNeeded(FormEntryPrompt prompt) {
    String autoplayOption = prompt.getFormElement().getAdditionalAttribute(null, AUTOPLAY_ATTRIBUTE);
    if (hasAudioAutoplay(autoplayOption)) {
        List<Clip> clipsToPlay = new ArrayList<>();
        Clip promptClip = getPromptClip(prompt);
        if (promptClip != null) {
            clipsToPlay.add(promptClip);
        }
        List<Clip> selectClips = getSelectClips(prompt);
        if (!selectClips.isEmpty()) {
            clipsToPlay.addAll(selectClips);
        }
        if (clipsToPlay.isEmpty()) {
            return false;
        } else {
            audioHelper.playInOrder(clipsToPlay);
            return true;
        }
    } else {
        return false;
    }
}
Also used : Clip(org.odk.collect.audioclips.Clip) ArrayList(java.util.ArrayList)

Example 4 with Clip

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

the class AudioWidget method updatePlayerMedia.

private void updatePlayerMedia() {
    if (binaryName != null) {
        Clip clip = new Clip("audio:" + getFormEntryPrompt().getIndex().toString(), getAudioFile().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) AudioWidgetAnswerBinding(org.odk.collect.android.databinding.AudioWidgetAnswerBinding) LengthFormatterKt.formatLength(org.odk.collect.strings.format.LengthFormatterKt.formatLength) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) FileWidget(org.odk.collect.android.widgets.interfaces.FileWidget) Appearances(org.odk.collect.android.utilities.Appearances) SuppressLint(android.annotation.SuppressLint) RecordingRequester(org.odk.collect.android.widgets.utilities.RecordingRequester) AnalyticsUtils(org.odk.collect.android.analytics.AnalyticsUtils) Locale(java.util.Locale) 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) LayoutInflater(android.view.LayoutInflater) 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) RecordingStatusHandler(org.odk.collect.android.widgets.utilities.RecordingStatusHandler) TypedValue(android.util.TypedValue) AudioFileRequester(org.odk.collect.android.widgets.utilities.AudioFileRequester) AudioControllerView(org.odk.collect.android.audio.AudioControllerView) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder)

Example 5 with Clip

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

the class AudioButtonIntegrationTest method pausingAndResumingActivity_andThenPressingPlay_startsClipFromTheBeginning.

@Test
public void pausingAndResumingActivity_andThenPressingPlay_startsClipFromTheBeginning() throws Exception {
    String testFile1 = File.createTempFile("audio1", ".mp3").getAbsolutePath();
    setupMediaPlayerDataSource(testFile1);
    AudioButton button = new AudioButton(activity);
    audioHelper.setAudio(button, new Clip("clip1", testFile1));
    button.performClick();
    shadowOf(mediaPlayer).setCurrentPosition(1000);
    fakeScheduler.runForeground();
    activityController.pause();
    activityController.resume();
    button.performClick();
    assertThat(mediaPlayer.getCurrentPosition(), equalTo(0));
}
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