ryanheise / just_audio

Audio Player
1.02k stars 627 forks source link

Incorrect AudioPlayer Position data on Android #1267

Open jennie-metacast opened 1 month ago

jennie-metacast commented 1 month ago

Which API doesn't behave as documented, and how does it misbehave?

Name here the specific methods or fields that are not behaving as documented

I think the _player.positionStream is incorrect:

explain clearly what is happening.

I am working on a podcast app that syncs the audio with a transcript. The logic for syncing is based on the player's position stream. The code detects the position within the audio file (e.g. 1500 seconds) and syncs to that location in the transcript. I have observed that there are times that the transcript syncing is off, and this is only observed on Android.

The root of the problem, from what I can tell, is that the player is reporting a position that is not the same as its actual position. I have been able to demonstrate this in a reproduction project (see below).

Minimal reproduction project

https://github.com/jennie-metacast/just_audio

To Reproduce (i.e. user steps, not code) Steps to reproduce the behavior:

  1. Run example_playlist.dart in Android emulator
  2. Play the first track - "55. Leaving Google and Amazon to bootstrap Metacast (rerun of ep. 24)"
  3. Click on the seek bar so that there is only 30-60 seconds left in the audio file
  4. Continue listening to the end of the track
  5. You will see that Position: 5568 and Duration: 5568, but the audio continues playing for a number of seconds (8-10) before switching to the next track.

As a point of contrast, if you follow the same steps running in an iOS simulator, the player position appears to be correct. I am inferring that it is correct based on the fact that when the position reaches 5568, it immediately transitions into the next audio track.

Error messages No error messages in the logs.

Expected behavior When the audio file gets to the end, it transitions immediately to the next track.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information): N/A

Smartphone (please complete the following information):

In this screen capture, you can see that Position: 5568 and Duration: 5568, but the audio continues playing for approximately 8 more seconds before switching to the next track.

Kapture 2024-06-17 at 13 04 18

Flutter SDK version

~/just_audio/just_audio (minor ✗) flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.19.6, on macOS 14.5 23F79 darwin-arm64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[✓] Android Studio (version 2023.2)
[✓] VS Code (version 1.89.1)
[✓] Connected device (2 available)
[✓] Network resources

! Doctor found issues in 1 category.

Additional context I think I have described this problem fully, but please let me know if any additional context is needed. I've searched through current open and closed issues and have not been able to find anything that seems directly related to this.

I also downloaded this specific track to see if it might somehow be related to the audio file's metadata, like an incorrect duration. However, the file's metadata appeared to be correct:

mediainfo --Output="General;%CompleteName%: %FileSize/String3% %Format/String% %Duration/String3% %OverallBitRate/String% %Album%" podcast.mp3

podcast.mp3: 128 MiB MPEG Audio 01:32:48.574 192 kb/s Metacast: Behind the scenes
jennie-metacast commented 1 month ago

Something I just noticed from the screen capture I posted - when the track does change to the next one in the playlist (Science Friday episode) the position is not 0. It starts at 9.