Search code examples
macosavplayerhttp-live-streaming

Using AAC with ID3 tags with AVPlayer


I have an AAC file with a bunch of ID3 tags that I captured from an HLS stream. I can play it back fine with AVPlayer. What I want to do is:

1) present the current ID3 tag to the user as the audio plays

2) get a list of all the unique ID3 tags so playback can jump to that location

I have found no way through the AVPlayer APIs to get the ID3 metadata. I could search through the AAC file for all the ID3 tags, but this would give me file byte offsets of the ID3 tags, and there does not seem to be a way to convert from a file byte offset to a time offset in order to jump playback to that location.


Solution

  • Every frame in an aac file starts with an ADTS header that contains its sample rate. And every frame is exactly 1024 samples. Hence every frame is sample_rate/1024 seconds long with the first frames starting at zero. From this, you can walk the file, and calculate every frames timestamp.