Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracting ID3 tags from MP3 over HTTP Live Streaming

I've been having quite a difficult time extracting ID3 information from an MP3 being streamed over Live HTTP Streaming (using the Wowza media server, if anyone is curious). I know that the tags (right now the album tag and the album artwork tag) are being properly embedded in each of the file segments because when I download them manually I can see them in each segment as listed in the .m3u index file generated by the server.

I am using the AVFoundation classes to do this, and I have it setup as such:

- (void)initializeAudioStream {
    NSURL *streamUrl = [NSURL URLWithString:self.urlField.text];
    AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:streamUrl];
    self.musicPlayer = [AVPlayer playerWithPlayerItem:playerItem];
    self.musicPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;
    [self.musicPlayer addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:NULL];
}

Once my KVO method is triggered, I start playing self.musicPlayer and I call addPeriodicTimeObserverForInterval on it for each 1/4 second. It is in this method that I try to extract the ID3 metadata.

I have tried everything I can think of on the iOS side of things to accomplish this, including printing out

self.musicPlayer.currentItem.asset.commonMetadata

as well as iterating over each of the AVAssetTrack instances and printing out their metadata.

for (AVAssetTrack *track in self.musicPlayer.currentItem.asset.tracks) {
    NSLog(@"Media type of track: %@", track.mediaType);
    NSLog(@"Track metadata: %@", track.commonMetadata);
}

What's interesting is that the asset always says it has 2 tracks. When I print out their mediaType property I get "soun" for the first one and "tmet" for the second. My assumption is that the first track is the audio data itself and the second track is metadata. However, I only ever see an empty array in commonMetadata.

I also check the status of the properties using statusOfValueForKey:error on the tracks, and the commonMetadata key always comes back as AVKeyValueStatusLoaded.

Any ideas? I'm at a complete loss here.

Also, I am currently running this through the iPhone 4 simulator running iOS 4.2.1. I can't yet put it on a device since Apple is still approving my company's developer account.

like image 833
Marc W Avatar asked Feb 23 '11 00:02

Marc W


People also ask

How do I remove ID3 tags from MP3 files?

Simply select the track, or tracks, that you wish to remove ID3 tags for, then right click them in the Music Tag file list. On the menu that appears, click the "Remove Tags" option.

How do I convert ID3 tags?

To change ID3 tags, right click in iTunes on the song that you need to change and select "Convert ID3 Tags".

What is ID3 tag MP3?

An ID3 tag is a type of metadata container used to store information into a media file (traditionally an MP3 audio file). The ID3 tags could include a title, an album title, the artist (author), genre, cover art, the year recorded and other details that are useful for the listener of your show.


1 Answers

Instead of using commonMetadata you might want to try using timedMetadata on the AVPlayerItem:

[playerItem addObserver:self forKeyPath:@"timedMetadata" options:NSKeyValueObservingOptionNew context:NULL];
like image 172
AdamH Avatar answered Oct 16 '22 14:10

AdamH