On 18 Jun '08, at 11:18 AM, Marco Papa wrote: and several open source libraries that will do the "tag extraction". There is at least one C++ library that should be easy to link with the Apple frameworks.
If you haven't found it yet, the one that I've used in the past is an Objective-C library called "ID3Tag.framework": It expects a file, though, so it might be difficult to get it to work on streamed data.
I assume the right place to look and extract the ID3v2 tags would be right at the beginning on the transaction, in response to the kCFStreamEventHasBytesAvailable event, before I pass the stream to Audio File Stream Services. This code would work like a proxy pass-through. Correct?
ID3v2 tags go at the beginning of the file. So if the stream is playing multiple tracks, like a typical radio station, there should be tags embedded in the data (in between the MPEG frames) wherever a new track/song begins. So realistically, you have to be ready to detect tags anywhere in the stream, since there's no other way to tell where a track begins.
(The original ID3v1 tags went at the _end_ of the file. This made them easier to update without having to rewrite the whole file, but obviously was not useable for streamed audio. I don't think you'd run into any of those.)
I've heard there is an additional protocol used by some streaming servers to let clients ask for the tags of the current track; otherwise if you start listening in the middle of one track, there's no way to get its tags, since they already went by before you tuned in. I don't know any details about that, though. The MP3 streaming protocol is sometimes called "Icecast", after one of the first implementations, so that might be a useful keyword to search on.
I think you're right about how to parse the tags. You'll need to do some buffering of the streamed data, though, because the tag boundaries won't necessarily match up with the chunks of the stream you read from the socket.
—Jens |