mirror of
https://github.com/androidx/media.git
synced 2025-05-17 20:49:53 +08:00

The logic has always been broken for multiple different reasons: - It applied usToMs twice, essentially making all calculations for the actual start time meaningless. - It compared against the fist observed timestamp after calling AudioTrack.play(), which may already include some advanced position. - The callback was falsely triggered after speed changes (when AudioTrack playback params are used). - It used the potentially smoothed position from different sources instead of using the latest reliable source - It did not wait until the getTimestamp source is reliable before triggering this callback (instead always relying on the more error-prone getPlaybackHeadPosition). As a result it has always reported the system time when we first observed a timestamp that was different from a previous one. We can make the callback more useful by fixing these points: - Wait until the getTimestamp source is reliably advancing or definitely can't be used (by which point we should also have a more reliable playbackHeadPosition value). - Calculate the start time using the latest position before applying any smoothing. - Save the "from" position in start() before AudioTrack.play() is called. This also avoid triggering the callback after speed changes. - Don't apply usToMs twice. PiperOrigin-RevId: 755927465