media icon indicating copy to clipboard operation
media copied to clipboard

getCurrentPosition is not strictly monotonic while playing

Open renaudcerrato opened this issue 1 year ago • 12 comments

Version

Media3 1.4.0

More version details

No response

Devices that reproduce the issue

Pixel 7 Pro (Android 14)

Devices that do not reproduce the issue

I assume none of them.

Reproducible in the demo app?

Not tested

Reproduction steps

I'm playing an MP4 audio while polling getCurrentPosition periodically to update the position, but I'm seeing some unexpected backward jump at around 3 seconds - the audio is playing fine - only the current position value seems wrong causing some unexpected UI glitches. It only seems to happen once, 3 seconds after playing started.

Confirmed using some debug traces:

position: 2.901s
position: 2.917s
position: 2.934s
position: 2.951s
position: 2.853s <--- here
position: 2.87s
position: 2.887s
position: 2.903s
position: 2.92s
position: 2.938s
position: 2.956s
position: 2.975s

Expected result

getCurrentPosition should be strictly monotonic during playing.

Actual result

getCurrentPosition randomly jumps backward.

Media

https://github.com/user-attachments/assets/65cf585e-a5b2-4920-966d-ac6b45a403fa

Bug Report

  • [ ] You will email the zip file produced by adb bugreport to [email protected] after filing this issue.

renaudcerrato avatar Jul 31 '24 08:07 renaudcerrato

@renaudcerrato,

Thanks for filing the issue! Can you please share the audio with which you saw this problem? You can send it to [email protected] if you don't want to share it publicly.

tianyif avatar Jul 31 '24 10:07 tianyif

Here it is:

https://github.com/user-attachments/assets/4835f933-6c63-4b01-aeca-929f517ad3a7

renaudcerrato avatar Jul 31 '24 11:07 renaudcerrato

Hi @renaudcerrato,

Thanks for sending the media. I quickly played it on the demo app and added some simple code to poll the player.getCurrentPosition() every 10 milliseconds (tried offload mode both on and off), but couldn't reproduce this issue. Did you see this problem every time when you play or from time to time? Did you turn on some special features on the player that don't come as default?

tianyif avatar Jul 31 '24 18:07 tianyif

Seeing this everytime, on every audio files around 3 seconds after play(). If I pause() or seek(), same behavior 3 seconds after play().

BTW: my exoplayer is running into a playback service, the UI bind using a MediaSession.

Will try to produce a minimal example as soon as possible.

renaudcerrato avatar Jul 31 '24 19:07 renaudcerrato

@renaudcerrato,

BTW: my exoplayer is running into a playback service, the UI bind using a MediaSession.

Thanks, this is really helpful information! Was this problem seen at your controller app? If yes, are you using media3 MediaController?

tianyif avatar Aug 01 '24 15:08 tianyif

Yes, seeing it from MediaController

renaudcerrato avatar Aug 02 '24 04:08 renaudcerrato

Hi @renaudcerrato,

Unfortunately I still couldn't reproduce this issue on the demo session app (with adding some code to have a controller poll the currentPosition every 10ms), is it possible for you to provide a minimum sample project that can reproduce this issue?

tianyif avatar Aug 13 '24 12:08 tianyif

Didn't had the time yet to produce a minimal POC due to holidays, but I'd be happy to privately share the project if you agree. Any means?

renaudcerrato avatar Aug 13 '24 12:08 renaudcerrato

@renaudcerrato, yes you can share it by sending the link to [email protected]. But please provide enough information on how to navigate to the part of code related to this issue.

tianyif avatar Aug 14 '24 13:08 tianyif

Just stripped down the project, here's a minimal working version (including recording to generate your sample): recorder.zip. Just record a sample for at least 3 seconds and then navigate to the playlist tab. You can even export your sample for further analyzes.

Should be straightforward to navigate.

The playback service is under src/recorder/service.

I've added some debug in the polling function in src/recorder/screen/player/MediaController.kt (MediaControllerState uses a SessionToken) :

image

image

This is a jetpack compose project, polling in a LaunchedEffect:

image

renaudcerrato avatar Aug 15 '24 06:08 renaudcerrato

I forgot to ping you @tianyif sorry

renaudcerrato avatar Aug 20 '24 10:08 renaudcerrato

I am seeing exactly the same behavior. In addition, even if the app is not calling getCurrentPosition itself, if the app uses a MediaSessionService to play media in the background, the MediaStyle notification provided by the library exhibits the same behavior: the playback position slider jumps back slightly at the 3 second mark. (This can be difficult to notice because the notification's playback position slider only updates several times per second.)

andrewfarm avatar Sep 20 '24 20:09 andrewfarm

I am also seeing this behaviour with MediaController (and it doesn't occur when directly accessing the player - which I can only do because it's in the same process) so I believe this is may be related to media3-session library, any chance someone could take a look?

nift4 avatar Jan 29 '25 17:01 nift4