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

Newreturntoloop #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions app/src/main/java/com/afxmusic/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ public void onClick(View view) {
mEndMarker.setVisibility(View.VISIBLE);

mSetLoopButton.setText("Clear loop");
mPlayButton.setBackgroundResource(R.drawable.pause);
}
}
});
Expand Down
30 changes: 28 additions & 2 deletions app/src/main/java/com/afxmusic/MediaPlayerHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,20 @@ public void setLoop(int loopMode, TextView startText, TextView endText) {
loopStart = loopEnd;
loopEnd = temp;
}
if (loopEnd == songLength) { //handle loopEnd is at very end of song
//Log.d(TAG, "LoopEnd == SongLength: " + loopEnd);
loopEnd -= 250;
//Log.d(TAG, "Changing LoopEnd: " + loopEnd);
}

startText.setText("Loop Start: " + convertToTime(loopStart));
endText.setText("Loop End: " + convertToTime(loopEnd));

looping = true;
mMediaPlayer.setLooping(false);
} else { // Clear loop
looping = false;
mMediaPlayer.setLooping(true);

startText.setText("Loop Start: N/A");
endText.setText("Loop End: N/A");
Expand Down Expand Up @@ -333,6 +340,23 @@ public double[] getTime(){
return time;
}

/** Same functionality as play() but
* is void and does not pause if playing already.
* Only plays.
* */
private void onlyPlay() {
if (mMediaPlayer != null){
startUpdatingCallbackWithPosition();
if(!mMediaPlayer.isPlaying()) {
mMediaPlayer.start();
mMediaPlayer.setPlaybackParams(mMediaPlayer.getPlaybackParams().setSpeed(speed));
if (mPlaybackInfoListener != null) {
mPlaybackInfoListener.onStateChanged(PlaybackInfoListener.State.PLAYING);
}
}
}
}

/**
* Syncs the mMediaPlayer position with mPlaybackProgressCallback via recurring task.
*/
Expand All @@ -348,9 +372,11 @@ public void run() {
// Looping
if (looping) {
int curr = mMediaPlayer.getCurrentPosition();
if (curr > loopEnd) {
// Log.d(TAG, "Looping back from " + loopEnd + " to " + loopStart);
if (curr >= songLength || curr >= loopEnd) {
//Log.d(TAG, "Looping back from " + loopEnd + " to " + loopStart);
mMediaPlayer.seekTo(loopStart);
onlyPlay();

}
}
}
Expand Down