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