mirror of
https://github.com/samsonjs/media.git
synced 2026-03-26 09:35:47 +00:00
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
This commit is contained in:
parent
00f84fc85f
commit
fb7ddb722c
2 changed files with 19 additions and 10 deletions
|
|
@ -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
|
||||
* {@link ExoPlayer#sendMessage} or {@link ExoPlayer#blockingSendMessage}. The message object
|
||||
* should be a {@link android.media.PlaybackParams}. This will be used to configure the
|
||||
* underlying {@link android.media.AudioTrack}.
|
||||
* should be a {@link android.media.PlaybackParams}, which will be used to configure the
|
||||
* 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;
|
||||
|
||||
|
|
|
|||
|
|
@ -1193,28 +1193,36 @@ public final class AudioTrack {
|
|||
private static class AudioTrackUtilV23 extends AudioTrackUtilV19 {
|
||||
|
||||
private PlaybackParams playbackParams;
|
||||
private float playbackSpeed;
|
||||
|
||||
public AudioTrackUtilV23() {
|
||||
playbackSpeed = 1.0f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reconfigure(android.media.AudioTrack audioTrack,
|
||||
boolean needsPassthroughWorkaround) {
|
||||
super.reconfigure(audioTrack, needsPassthroughWorkaround);
|
||||
setPlaybackParameters(playbackParams);
|
||||
maybeApplyPlaybackParams();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlaybackParameters(PlaybackParams playbackParams) {
|
||||
playbackParams = (playbackParams != null ? playbackParams : new PlaybackParams())
|
||||
.allowDefaults();
|
||||
this.playbackParams = playbackParams;
|
||||
if (audioTrack != null && playbackParams != null) {
|
||||
audioTrack.setPlaybackParams(playbackParams);
|
||||
}
|
||||
this.playbackSpeed = playbackParams.getSpeed();
|
||||
maybeApplyPlaybackParams();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPlaybackSpeed() {
|
||||
if (playbackParams != null) {
|
||||
return playbackParams.getSpeed();
|
||||
} else {
|
||||
return 1.0f;
|
||||
return playbackSpeed;
|
||||
}
|
||||
|
||||
private void maybeApplyPlaybackParams() {
|
||||
if (audioTrack != null && playbackParams != null) {
|
||||
audioTrack.setPlaybackParams(playbackParams);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue