Commit fb7ddb72 by olly Committed by Oliver Woodman

Minor tweaks to AudioTrack playback params logic.

- Use allowDefaults to fix crash if params are passed without
  the speed being explicitly set.
- Allow null to be passed to clear previously set params.
- Clarify in doc that the passed params shouldn't be modified
  after they're passed.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=109591580
parent 00f84fc8
...@@ -80,8 +80,9 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer implem ...@@ -80,8 +80,9 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer implem
/** /**
* The type of a message that can be passed to an instance of this class via * The type of a message that can be passed to an instance of this class via
* {@link ExoPlayer#sendMessage} or {@link ExoPlayer#blockingSendMessage}. The message object * {@link ExoPlayer#sendMessage} or {@link ExoPlayer#blockingSendMessage}. The message object
* should be a {@link android.media.PlaybackParams}. This will be used to configure the * should be a {@link android.media.PlaybackParams}, which will be used to configure the
* underlying {@link android.media.AudioTrack}. * underlying {@link android.media.AudioTrack}. The message object should not be modified by the
* caller after it has been passed
*/ */
public static final int MSG_SET_PLAYBACK_PARAMS = 2; public static final int MSG_SET_PLAYBACK_PARAMS = 2;
......
...@@ -1193,28 +1193,36 @@ public final class AudioTrack { ...@@ -1193,28 +1193,36 @@ public final class AudioTrack {
private static class AudioTrackUtilV23 extends AudioTrackUtilV19 { private static class AudioTrackUtilV23 extends AudioTrackUtilV19 {
private PlaybackParams playbackParams; private PlaybackParams playbackParams;
private float playbackSpeed;
public AudioTrackUtilV23() {
playbackSpeed = 1.0f;
}
@Override @Override
public void reconfigure(android.media.AudioTrack audioTrack, public void reconfigure(android.media.AudioTrack audioTrack,
boolean needsPassthroughWorkaround) { boolean needsPassthroughWorkaround) {
super.reconfigure(audioTrack, needsPassthroughWorkaround); super.reconfigure(audioTrack, needsPassthroughWorkaround);
setPlaybackParameters(playbackParams); maybeApplyPlaybackParams();
} }
@Override @Override
public void setPlaybackParameters(PlaybackParams playbackParams) { public void setPlaybackParameters(PlaybackParams playbackParams) {
playbackParams = (playbackParams != null ? playbackParams : new PlaybackParams())
.allowDefaults();
this.playbackParams = playbackParams; this.playbackParams = playbackParams;
if (audioTrack != null && playbackParams != null) { this.playbackSpeed = playbackParams.getSpeed();
audioTrack.setPlaybackParams(playbackParams); maybeApplyPlaybackParams();
}
} }
@Override @Override
public float getPlaybackSpeed() { public float getPlaybackSpeed() {
if (playbackParams != null) { return playbackSpeed;
return playbackParams.getSpeed(); }
} else {
return 1.0f; private void maybeApplyPlaybackParams() {
if (audioTrack != null && playbackParams != null) {
audioTrack.setPlaybackParams(playbackParams);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment