Skip to content

Commit

Permalink
#730: Don't ever call MediaPlayer.setPlaybackParams before playback s…
Browse files Browse the repository at this point in the history
…tarts
  • Loading branch information
daneren2005 committed Aug 25, 2016
1 parent 1c72aa2 commit a05ecac
Showing 1 changed file with 4 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,7 @@ private synchronized void playNext(boolean start) {
setCurrentPlaying(nextPlaying, true);
setPlayerState(PlayerState.STARTED);
setupHandlers(currentPlaying, false, start);
applyPlaybackParamsMain();
setNextPlaying();

// Proxy should not be being used here since the next player was already setup to play
Expand Down Expand Up @@ -1300,6 +1301,7 @@ public synchronized void start() {
// Only start if done preparing
if(playerState != PREPARING) {
mediaPlayer.start();
applyPlaybackParamsMain();
} else {
// Otherwise, we need to set it up to start when done preparing
autoPlayStart = true;
Expand Down Expand Up @@ -1887,10 +1889,10 @@ public void onPrepared(MediaPlayer mediaPlayer) {
cachedPosition = position;

applyReplayGain(mediaPlayer, downloadFile);
applyPlaybackParams(mediaPlayer);

if (start || autoPlayStart) {
mediaPlayer.start();
applyPlaybackParamsMain();
setPlayerState(STARTED);

// Disable autoPlayStart after done
Expand Down Expand Up @@ -1958,7 +1960,6 @@ public void onPrepared(MediaPlayer mp) {
}

applyReplayGain(nextMediaPlayer, downloadFile);
applyPlaybackParamsNext();
} catch (Exception x) {
handleErrorNext(x);
}
Expand Down Expand Up @@ -2617,9 +2618,6 @@ public void setPlaybackSpeed(float playbackSpeed) {
if(mediaPlayer != null && (playerState == PREPARED || playerState == STARTED || playerState == PAUSED || playerState == PAUSED_TEMP)) {
applyPlaybackParamsMain();
}
if(nextMediaPlayer != null && nextPlayerState == PREPARED) {
applyPlaybackParamsNext();
}

delayUpdateProgress = Math.round(DEFAULT_DELAY_UPDATE_PROGRESS / playbackSpeed);
}
Expand All @@ -2634,11 +2632,6 @@ public float getPlaybackSpeed() {
private synchronized void applyPlaybackParamsMain() {
applyPlaybackParams(mediaPlayer);
}
private synchronized void applyPlaybackParamsNext() {
if(isNextPlayingSameAlbum()) {
applyPlaybackParams(nextMediaPlayer);
}
}
private synchronized boolean isNextPlayingSameAlbum() {
return isNextPlayingSameAlbum(currentPlaying, nextPlaying);
}
Expand All @@ -2654,7 +2647,7 @@ private synchronized void applyPlaybackParams(MediaPlayer mediaPlayer) {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
float playbackSpeed = getPlaybackSpeed();

if(playbackSpeed != 1.0f || mediaPlayer.getPlaybackParams() != null) {
if(Math.abs(playbackSpeed - 1.0) > 0.01 || mediaPlayer.getPlaybackParams() != null) {
PlaybackParams playbackParams = new PlaybackParams();
playbackParams.setSpeed(playbackSpeed);
mediaPlayer.setPlaybackParams(playbackParams);
Expand Down

0 comments on commit a05ecac

Please sign in to comment.