Estimate content position when playWhenReady never has changed

This change closes an edge case when an app is connecting a controller to a session that is already playing. In such a case `MediaControllerImplBase.getContentPosition()` keeps returning the first estimation for every call until `playWhenReady` changes for the first time.

Reproduction: Launch the demo-session app and start audio playback. Put the activity to the background and then to the foreground again. Go to the playlist view and `PlayerActivity` without interrupting playback and try to seek in the timebar. The position is stuck and snaps back.
PiperOrigin-RevId: 422795360
This commit is contained in:
bachinger 2022-01-19 14:08:00 +00:00 committed by Ian Baker
parent e77417b004
commit 491ac8f066

View file

@ -677,8 +677,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
@Override
public long getContentPosition() {
boolean receivedUpdatedPositionInfo =
lastSetPlayWhenReadyCalledTimeMs != C.TIME_UNSET
&& lastSetPlayWhenReadyCalledTimeMs < playerInfo.sessionPositionInfo.eventTimeMs;
lastSetPlayWhenReadyCalledTimeMs < playerInfo.sessionPositionInfo.eventTimeMs;
if (!playerInfo.isPlaying || playerInfo.sessionPositionInfo.isPlayingAd) {
if (receivedUpdatedPositionInfo || lastReturnedContentPositionMs == C.TIME_UNSET) {
lastReturnedContentPositionMs =