From f823e75e564ed34204a21c214ecce6daa16b96a0 Mon Sep 17 00:00:00 2001 From: mxaln Date: Wed, 10 Jul 2019 16:09:22 -0400 Subject: [PATCH] Source Audio and Recording should not play simultaneously --- .../Playback/PlaybackActivity.java | 13 ++++++++++++- .../Playback/SourceAudio.java | 16 ++++++++++++++++ .../Playback/fragments/FragmentTabbedWidget.java | 9 +++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/translationRecorder/app/src/main/java/org/wycliffeassociates/translationrecorder/Playback/PlaybackActivity.java b/translationRecorder/app/src/main/java/org/wycliffeassociates/translationrecorder/Playback/PlaybackActivity.java index d68468a30..194be4071 100644 --- a/translationRecorder/app/src/main/java/org/wycliffeassociates/translationrecorder/Playback/PlaybackActivity.java +++ b/translationRecorder/app/src/main/java/org/wycliffeassociates/translationrecorder/Playback/PlaybackActivity.java @@ -95,7 +95,8 @@ public class PlaybackActivity extends Activity implements FragmentFileBar.RatingCallback, FragmentFileBar.InsertCallback, DraggableImageView.OnMarkerMovementRequest, - ExitDialog.DeleteFileCallback + ExitDialog.DeleteFileCallback, + SourceAudio.OnAudioListener { public enum MODE { @@ -294,11 +295,21 @@ public void onMediaPause() { public void onMediaPlay() { try { mAudioController.play(); + mFragmentTabbedWidget.getSrcPlayer().pauseSource(); } catch (IllegalStateException e) { requestUserToRestart(); } } + @Override + public void onSourcePlay() { + mAudioController.pause(); + mFragmentPlaybackTools.showPlayButton(); + } + + @Override + public void onSourcePause() {} + public void requestUserToRestart() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Could not initialize the audio player"); diff --git a/translationRecorder/app/src/main/java/org/wycliffeassociates/translationrecorder/Playback/SourceAudio.java b/translationRecorder/app/src/main/java/org/wycliffeassociates/translationrecorder/Playback/SourceAudio.java index e58f4723a..2b2f158bd 100644 --- a/translationRecorder/app/src/main/java/org/wycliffeassociates/translationrecorder/Playback/SourceAudio.java +++ b/translationRecorder/app/src/main/java/org/wycliffeassociates/translationrecorder/Playback/SourceAudio.java @@ -50,8 +50,14 @@ public class SourceAudio extends LinearLayout { private String mFileName; private int mChapter; private File mTemp; + private OnAudioListener sourceAudioListener; private static final String[] filetypes = {"wav", "mp3", "mp4", "m4a", "aac", "flac", "3gp", "ogg"}; + public interface OnAudioListener { + void onSourcePlay(); + void onSourcePause(); + } + public SourceAudio(Context context) { this(context, null); } @@ -205,10 +211,16 @@ public void initSrcAudio(Project project, String fileName, int chapter){ public void playSource() { mSrcPlayer.play(); + if(sourceAudioListener != null) { + sourceAudioListener.onSourcePlay(); + } } public void pauseSource(){ mSrcPlayer.pause(); + if(sourceAudioListener != null) { + sourceAudioListener.onSourcePause(); + } } public void reset(Project project, String fileName, int chapter){ @@ -249,4 +261,8 @@ public void showNoSource(boolean noSource) { setEnabled(true); } } + + public void setSourceAudioListener(OnAudioListener listener) { + sourceAudioListener = listener; + } } diff --git a/translationRecorder/app/src/main/java/org/wycliffeassociates/translationrecorder/Playback/fragments/FragmentTabbedWidget.java b/translationRecorder/app/src/main/java/org/wycliffeassociates/translationrecorder/Playback/fragments/FragmentTabbedWidget.java index 11b012338..8d3db14e8 100644 --- a/translationRecorder/app/src/main/java/org/wycliffeassociates/translationrecorder/Playback/fragments/FragmentTabbedWidget.java +++ b/translationRecorder/app/src/main/java/org/wycliffeassociates/translationrecorder/Playback/fragments/FragmentTabbedWidget.java @@ -23,6 +23,7 @@ import org.wycliffeassociates.translationrecorder.Playback.overlays.TimecodeLayer; import org.wycliffeassociates.translationrecorder.project.Project; import org.wycliffeassociates.translationrecorder.R; +import org.wycliffeassociates.translationrecorder.widgets.AudioPlayer; /** * Created by sarabiaj on 11/4/2016. @@ -47,6 +48,7 @@ public class FragmentTabbedWidget extends Fragment implements MinimapLayer.Minim ViewCreatedCallback mViewCreatedCallback; MediaController mMediaController; + SourceAudio.OnAudioListener mAudioListener; String mFilename = ""; Project mProject; @@ -88,6 +90,7 @@ public void onAttach(Activity activity) { mMediaController = (MediaController) activity; mMinimapDrawDelegator = (MinimapLayer.MinimapDrawDelegator) activity; mMinimapLineDrawDelegator = (DelegateMinimapMarkerDraw) activity; + mAudioListener = (SourceAudio.OnAudioListener) activity; } @Override @@ -181,6 +184,8 @@ public void onClick(View v) { mSwitchToMinimap.setBackgroundColor(getResources().getColor(R.color.mostly_black)); } }); + + mSrcPlayer.setSourceAudioListener(mAudioListener); } @Override @@ -196,6 +201,10 @@ public void onDestroy() { mViewCreatedCallback = null; } + public SourceAudio getSrcPlayer() { + return mSrcPlayer; + } + public void initializeTimecode(int durationMs){ mTimecodeLayer.setAudioLength(durationMs); }