Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android Auto ExoPlayer seeking of the audio track creates error while seeking to the end of the track #1563

Closed
1 task
parkbrakereminder opened this issue Jul 24, 2024 · 10 comments
Assignees

Comments

@parkbrakereminder
Copy link

Version

Media3 pre-release (alpha, beta or RC not in this list)

More version details

I used v1.3.1 with experiencing the error while testing in the vehicle, then reproduced on the Desktop Head Unit simulator. Linking my finding to the issue #1376, #1376.
Reproduction is on the tracks with the non-MP3 data at the end of the file.
Issue is present w v1.4.1-rc01
Issue is disappers by downgrading to v1.2.1

Devices that reproduce the issue

Samsung
+Desktop Head Unit
or any vehicle system w Android Auto, since UI is part of the companion device, so the seeking bar.

ExoPlayer versions >1.2.1

Devices that do not reproduce the issue

ExoPlayer versions = 1.2.1

Reproducible in the demo app?

Yes

Reproduction steps

play song w non-MP3 data inside the file and seek to the end of the file, while playing

Expected result

turn over to the next song in the playlist

Actual result

Source Error, player stops playing and freezes, by pushing the button to jump to the next song on the controls outside the player and then push play button -> next song is playing. So, I came to the MP3 Exractor Issue, related to wrong calculation of the file lenght.

Media

Screenshot 2024-07-24 183138
No_issue-w1 2 1
No_Issue-w1 2 1_dependencies
Screenshot 2024-07-24 183018
Screenshot 2024-07-24 183101

Bug Report

@icbaker
Copy link
Collaborator

icbaker commented Jul 24, 2024

Please can you provide us with the MP3 file that causes this issue?
Please either upload it here or send it to android-media-github@google.com with the subject Issue #1563. Please also update this issue to indicate you’ve done this.

@parkbrakereminder
Copy link
Author

Please can you provide us with the MP3 file that causes this issue? Please either upload it here or send it to android-media-github@google.com with the subject Issue #1563. Please also update this issue to indicate you’ve done this.

Hi Ian, I have sent the file via email.

@icbaker
Copy link
Collaborator

icbaker commented Jul 31, 2024

Thanks for providing the media, this looks like a duplicate of #1480

@parkbrakereminder
Copy link
Author

Hi Ian, does it mean, the issue will be fixed in the 1.4.x version of ExoPlayer?

@parkbrakereminder
Copy link
Author

parkbrakereminder commented Aug 3, 2024 via email

@icbaker
Copy link
Collaborator

icbaker commented Aug 5, 2024

Please see #1480 (comment)

@icbaker icbaker closed this as completed Aug 5, 2024
@icbaker icbaker closed this as not planned Won't fix, can't repro, duplicate, stale Aug 5, 2024
@parkbrakereminder
Copy link
Author

Hi Ian,

I changed to 1,4,1 ExoPlayer as it shall fix the problem, but some song tracks are still producing the same error as before. I have written an email to you, w the MP3 attached, which leads to the failure again, while seeking to the end of the song, or if it is playing to the end by itself without seeking manually.

Could you please check again, what is wrong with the lenght calculation inside the MP3 Extactor?
image

image

Thx upfront!

@tonihei tonihei reopened this Aug 28, 2024
@icbaker
Copy link
Collaborator

icbaker commented Aug 28, 2024

Thanks for sharing the media.

This file is CBR but contains non-MP3 data at the end of the file after byte 9268060 (the end of the last MP3 packet [1]). The file is 9428879 bytes long, so that's 9428879 - 9268060 = 160819 = 161kB of extra non-MP3 data.

It also contains non-audio data at the start of the file (but within an MP3 frame), so the audio doesn't start until byte 161775.

The file doesn't seem to contain any metadata at the start to indicate to a player how long the MP3 data is, so we have to assume it extends to the end. This means:

  1. Since we derive the duration of the file from the number of audio bytes and bitrate (since the file is CBR), we calculate an incorrect duration
    • We calculate the audio length as fileLength - startOfAudio = 9428879 - 161775 = 9267104 bytes, which at 320kbps is 9267104 * 8 / 320000 = 231.68s = 3m51.68s
    • The timestamp of the end of the last frame (from ffprobe [1]) is 227.631020 + 0.026122 =
  2. When we reach the end of the file, we crash because the data stops looking like MP3 data.

This error occurs on both 1.2.1 and 1.4.1 (unlike the file you originally shared in this issue), so this isn't a regression.

google/ExoPlayer#5718 tracks the similar case of non-MP3 data at the beginning of a file.

It's worth noting that VLC also can't handle this file correctly. It also says the duration is 3:51 but audio stops early and the progress bar suddenly jumps to the end.

I have modified Mp3Extractor locally to treat the case of "can't find the next MP3 header" as "end of file" rather than "fail playback". This changes the behaviour to be a bit more similar to VLC - playback no longer fails at the end, but it is silent until the position reaches 3:52 (rather than jumping to the end when the MP3 data is exhausted). I've sent this for review, and we will discuss as a team if this is a change we want to make to the library - possibly behind an extractor flag.


[1] From ffprobe:

$ ffprobe -show_packets ghi-1563-caliban.mp3
...
[PACKET]
codec_type=audio
stream_index=0
pts=3212328960
pts_time=227.631020
dts=3212328960
dts_time=227.631020
duration=368640
duration_time=0.026122
size=1045
pos=9267015
flags=K__
[/PACKET]

copybara-service bot pushed a commit that referenced this issue Sep 2, 2024
The `bear-cbr-no-seek-table-trailing-garbage.mp3` test file was generated by appending 150kB of `0xDEADBEEF` onto the end of `bear-cbr-variable-frame-size-no-seek-table.mp3`.

Issue: #1563

#cherrypick

PiperOrigin-RevId: 670131828
@icbaker
Copy link
Collaborator

icbaker commented Sep 2, 2024

The commit above resolves the crash, instead playback jumps suddenly to the end when it encounters enough non-MP3 data. This means the duration of files like this is still shown incorrectly (until the loading position reaches the end), but there's not really anything we can do about this because the file doesn't contain enough info to know in advance how long the MP3 data is (and therefore its duration).

@icbaker icbaker closed this as completed Sep 2, 2024
@parkbrakereminder
Copy link
Author

parkbrakereminder commented Sep 9, 2024 via email

@androidx androidx locked and limited conversation to collaborators Nov 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants