Skip to content

fix(Mp4): play local M4A files whose moov atom starts after the first read - #154

Open
jrmmhm wants to merge 2 commits into
dimitris-c:mainfrom
jrmmhm:fix-mp4-probe-forward
Open

jrmmhm wants to merge 2 commits into
dimitris-c:mainfrom
jrmmhm:fix-mp4-probe-forward

Conversation

@jrmmhm

@jrmmhm jrmmhm commented Nov 11, 2026

Copy link
Copy Markdown

Some local M4A files don't play at all: the player reports "The specified file type is not supported" and nothing starts. It happens with files that are already optimized for streaming, but whose header (the moov atom) begins after the first 64 KiB of the file, for example because a large free atom sits in front of it.

The cause is small. When the first chunk is not enough to tell whether the file is optimized, FileAudioSource reads on and keeps the chunks in a buffer. Once it knew the answer, it passed on only the last chunk and dropped the earlier ones, so the parser never saw the start of the file. Now it passes on the whole buffer. Files that are decided on the first read, and files that need restructuring, behave as before.

The tests cover this layout and those two unchanged cases, and one test plays a 2 second file of this layout to its end. Without the fix the two new cases fail and the two others pass.

I don't know how common such files are. I ran into this while looking at playback problems in Amperfy. Besides the tests on macOS I played such a file from the cache on an iPhone in a private Amperfy build; I did not compare it there without the fix. The fixture is 91 KB, and I can add the script that generates it if you'd like.

When FileAudioSource needed more than one read to decide that a local MP4 is already optimized, only the last chunk reached the parser and the earlier probe bytes, including the ftyp atom, were dropped.
Unit tests check that FileAudioSource hands every probed byte to the parser, with two controls for the first-read and restructure paths. A player test plays a short AAC fixture whose moov atom starts beyond the first 64 KiB read to its end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant