Added playback params to wrapper so speed can be changed while paused

You can't modify playback params on the ExoPlayer while paused (see
https://github.com/google/ExoPlayer/issues/4064) so added a member
object which *can* be modified while playback is paused. These
parameters are always applied on start of playback.

Fixes #3651
This commit is contained in:
Jonas Kalderstam 2019-12-01 21:50:31 +01:00
parent 90f578aa48
commit 407e70ad2b
1 changed files with 7 additions and 3 deletions

View File

@ -46,11 +46,13 @@ public class ExoPlayerWrapper implements IPlayer {
private MediaPlayer.OnCompletionListener audioCompletionListener; private MediaPlayer.OnCompletionListener audioCompletionListener;
private MediaPlayer.OnErrorListener audioErrorListener; private MediaPlayer.OnErrorListener audioErrorListener;
private MediaPlayer.OnBufferingUpdateListener bufferingUpdateListener; private MediaPlayer.OnBufferingUpdateListener bufferingUpdateListener;
private PlaybackParameters playbackParameters;
ExoPlayerWrapper(Context context) { ExoPlayerWrapper(Context context) {
mContext = context; mContext = context;
mExoPlayer = createPlayer(); mExoPlayer = createPlayer();
playbackParameters = mExoPlayer.getPlaybackParameters();
bufferingUpdateDisposable = Observable.interval(2, TimeUnit.SECONDS) bufferingUpdateDisposable = Observable.interval(2, TimeUnit.SECONDS)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
@ -145,7 +147,7 @@ public class ExoPlayerWrapper implements IPlayer {
@Override @Override
public float getCurrentSpeedMultiplier() { public float getCurrentSpeedMultiplier() {
return mExoPlayer.getPlaybackParameters().speed; return playbackParameters.speed;
} }
@Override @Override
@ -225,8 +227,8 @@ public class ExoPlayerWrapper implements IPlayer {
@Override @Override
public void setPlaybackParams(float speed, boolean skipSilence) { public void setPlaybackParams(float speed, boolean skipSilence) {
PlaybackParameters params = mExoPlayer.getPlaybackParameters(); playbackParameters = new PlaybackParameters(speed, playbackParameters.pitch, skipSilence);
mExoPlayer.setPlaybackParameters(new PlaybackParameters(speed, params.pitch, skipSilence)); mExoPlayer.setPlaybackParameters(playbackParameters);
} }
@Override @Override
@ -247,6 +249,8 @@ public class ExoPlayerWrapper implements IPlayer {
@Override @Override
public void start() { public void start() {
mExoPlayer.setPlayWhenReady(true); mExoPlayer.setPlayWhenReady(true);
// Can't set params when paused - so always set it on start in case they changed
mExoPlayer.setPlaybackParameters(playbackParameters);
} }
@Override @Override