We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4410

Summary: mpg123 doesn't store original file offset, causing seek errors when playing
Product: SDL_mixer Reporter: Anthony @ POW Games <ant>
Component: miscAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: sezeroz
Version: 2.0.4   
Hardware: All   
OS: All   
Attachments: Test code to reproduce the bug
test data file containing MP3 data at offset 69531

Description Anthony @ POW Games 2018-12-03 12:48:04 UTC
When using Mix_LoadMUS_RW to load an MP3 that is part of a large file containing multiple MP3s, seeking errors will occure when attempting to play. Apparently the original file offset is not saved, so it presumably seeks from the beginning of the file, rather than beginning of the MP3 inside the file.
Comment 1 Anthony @ POW Games 2018-12-03 15:08:58 UTC
Created attachment 3521 [details]
Test code to reproduce the bug
Comment 2 Anthony @ POW Games 2018-12-03 15:09:55 UTC
Created attachment 3522 [details]
test data file containing MP3 data at offset 69531
Comment 3 Anthony @ POW Games 2018-12-03 15:15:00 UTC
Here's the test code and a test data file containing MP3 data at offset 69531.

I've found out that it's a little more complicated than mpg123 not storing the original offset because everything works if the offset is less than about 65K (there's a clue there). Once the MP3 offset is higher than about 65k, then the MP3 doesn't play. Maybe the offset is stored in, or filtered through a Uint16?

Note that this test code doesn't return any errors, even if playing fails. This is a very small MP3 file for testing. In my big project there's a lot more going on and big MP3 files, and it was returning seek errors.  But this test code still demonstrates the error. I tested on a data file with low offsets and it worked ok. The MP3 loads no problem, proving that the MP3 file and offset are correct. If you try to play the MP3 again and again in the main look, you can hear a quiet clicking, so something is happening.
Comment 4 Ozkan Sezer 2018-12-24 09:35:03 UTC
This shouldn't be limited to mp3 (mpg123): the ogg player doesn't
store the original offset either.  (Only mikmod player does that,
I think..)
Comment 5 Ozkan Sezer 2021-01-28 03:51:12 UTC
I have a one-liner fix for your specific issue in the current
development SDL_mixer tree, but SDL_RWsize() can be problematic
(bug #5509.)
Comment 6 Ozkan Sezer 2021-01-28 14:05:38 UTC
Fixed as of https://hg.libsdl.org/SDL_mixer/rev/16645c8ed64a
for next SDL2_mixer release. (Please confirm.)

Fix also applied to SDL-1.2 branch:
https://hg.libsdl.org/SDL_mixer/rev/ad8fd052d556