Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source Audio and Recording should not play simultaneously #1155

Merged
merged 1 commit into from
Jul 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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");
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