This project has moved and is read-only. For the latest updates, please go here.

Reading metadata tags from aac/mp3 streams

Jul 29, 2014 at 5:55 PM
Hi,

I would like know is it possible to read metadata (like author / title) when streaming mp3/aac files?
If yes, how can I do it? Any suggestions?
Coordinator
Jul 29, 2014 at 8:22 PM
You can see where the code skips the ID3v2 tag in Mp3Parser.cs. The code in ProcessData() that skips the tag looks like this:
            if (_skip > 0)
            {
                if (_skip >= length)
                {
                    _skip -= length;
                    return;
                }

                offset += _skip;
                length -= _skip;
                _skip = 0;
            }
You would need to change this code to feed the skipped data to something that decodes it. Note that the data may come in multiple chunks, so you may need to buffer the tag before submitting it to an ID3v2 decoding library. Something like this, I think:
            if (_skip > 0)
            {
                if (_skip >= length)
                {
                    _skip -= length;

                    _id3Consumer.BufferTag(buffer, offset, length);

                    return;
                }

                _id3Consumer.BufferTag(buffer, offset, _skip);

                 // IMPORTANT: Do not block here (e.g,, don't wait on the UI).  Start a TPL task if needed.
                _id3Consumer.ParseTag();

                offset += _skip;
                length -= _skip;
                _skip = 0;
            }
Assuming that your .aac streams have ID3v2 tags, you would need to change AacParser.cs so that it does the same thing as the MP3 parser. I think you can just copy the "_skip" related code from Mp3Parser.cs.
Jul 30, 2014 at 4:58 PM
Edited Jul 30, 2014 at 5:02 PM
Thanks for the reply. Currently the problem is my stream does not contain full metadata. To force this I would like to add a http header "Icy-MetaData: 1". But I have no idea where to inject this. Any help?

EDIT: I've managed to add the header in the OpenStream method of the SegmentReader class. Now I'm trying to parse the response.
Coordinator
Jul 31, 2014 at 10:08 AM
If the ICY headers are not showing up in the response headers, then the Microsoft HTTP stack doesn't like them. I'm not sure how to get it to stop hiding such headers.

For a simple stream like this, you might try using a StreamSocket directly. This could be done with a custom IWebReader/IWebReaderManager. One could also use another HTTP stack. I mean to clean this up at some point, but for now, this is decidedly "as-is": SM.Mono.Net. The simplest way to do this would probably be to copy the SM.Media/Web/WebRequestReader directory and changing the references to point to the SM.Mono.Net equivalents (I haven't actually tried this myself).
Jul 31, 2014 at 2:43 PM
After adding the header the metadata comes back. But now the stream starts to stutter every second or two. I guess some more data comes back and the aac can't handle it. Any help?
Coordinator
Jul 31, 2014 at 9:00 PM
I think the stutters are from the metadata. A quick web search turned up this page: Shoutcast Metadata Protocol