Fix position ramping behavior with AudioTrack speed params

Non-realtime AudioTrack playback speed was not taken into account when
extrapolating the old mode's position, causing the position not to
advance smoothly.

This should be a no-op when not using AudioTrack playback params for
speed adjustment.

Issue: #7982
PiperOrigin-RevId: 334151163
This commit is contained in:
andrewlewis 2020-09-28 15:15:26 +01:00 committed by Andrew Lewis
parent c95e43d9bd
commit 6b13640eeb
2 changed files with 7 additions and 1 deletions

View file

@ -22,6 +22,9 @@
([#7962](https://github.com/google/ExoPlayer/issues/7962)).
* Audio:
* Retry playback after some types of `AudioTrack` error.
* Fix the default audio sink position not advancing correctly when using
`AudioTrack`-based speed adjustment
([#7982](https://github.com/google/ExoPlayer/issues/7982)).
* Extractors:
* Add support for .mp2 boxes in the `AtomParsers`
([#7967](https://github.com/google/ExoPlayer/issues/7967)).

View file

@ -289,7 +289,10 @@ import java.lang.reflect.Method;
if (elapsedSincePreviousModeUs < MODE_SWITCH_SMOOTHING_DURATION_US) {
// Use a ramp to smooth between the old mode and the new one to avoid introducing a sudden
// jump if the two modes disagree.
long previousModeProjectedPositionUs = previousModePositionUs + elapsedSincePreviousModeUs;
long previousModeProjectedPositionUs =
previousModePositionUs
+ Util.getMediaDurationForPlayoutDuration(
elapsedSincePreviousModeUs, audioTrackPlaybackSpeed);
// A ramp consisting of 1000 points distributed over MODE_SWITCH_SMOOTHING_DURATION_US.
long rampPoint = (elapsedSincePreviousModeUs * 1000) / MODE_SWITCH_SMOOTHING_DURATION_US;
positionUs *= rampPoint;