Skip to content

Commit

Permalink
Source Audio and Recording should not play simultaneously (#1155)
Browse files Browse the repository at this point in the history
  • Loading branch information
mXaln authored and jsarabia committed Jul 15, 2019
1 parent a3f35b2 commit e026b9f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -295,11 +296,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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -249,4 +261,8 @@ public void showNoSource(boolean noSource) {
setEnabled(true);
}
}

public void setSourceAudioListener(OnAudioListener listener) {
sourceAudioListener = listener;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -47,6 +48,7 @@ public class FragmentTabbedWidget extends Fragment implements MinimapLayer.Minim

ViewCreatedCallback mViewCreatedCallback;
MediaController mMediaController;
SourceAudio.OnAudioListener mAudioListener;

String mFilename = "";
Project mProject;
Expand Down Expand Up @@ -88,6 +90,7 @@ public void onAttach(Activity activity) {
mMediaController = (MediaController) activity;
mMinimapDrawDelegator = (MinimapLayer.MinimapDrawDelegator) activity;
mMinimapLineDrawDelegator = (DelegateMinimapMarkerDraw) activity;
mAudioListener = (SourceAudio.OnAudioListener) activity;
}

@Override
Expand Down Expand Up @@ -181,6 +184,8 @@ public void onClick(View v) {
mSwitchToMinimap.setBackgroundColor(getResources().getColor(R.color.mostly_black));
}
});

mSrcPlayer.setSourceAudioListener(mAudioListener);
}

@Override
Expand All @@ -196,6 +201,10 @@ public void onDestroy() {
mViewCreatedCallback = null;
}

public SourceAudio getSrcPlayer() {
return mSrcPlayer;
}

public void initializeTimecode(int durationMs){
mTimecodeLayer.setAudioLength(durationMs);
}
Expand Down

0 comments on commit e026b9f

Please sign in to comment.