Assuming that you already know what kind of metadata is being sent from the stream (if you don't, use a media player like VLC to see), you must first register a notification to get the metadata in timed intervals and then a method to process them.
Starting with the notification, just
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(MetadataUpdate:)
name:MPMoviePlayerTimedMetadataUpdatedNotification
object:nil];
after the MPMoviePlayerController allocation.
Then on the MetadataUpdate method
- (void)MetadataUpdate:(NSNotification*)notification
{
if ([streamAudioPlayer timedMetadata]!=nil && [[streamAudioPlayer timedMetadata] count] > 0) {
MPTimedMetadata *firstMeta = [[streamAudioPlayer timedMetadata] objectAtIndex:0];
metadataInfo = firstMeta.value;
}
}
where streamAudioplayer is your MPMoviePlayerController and metadataInfo a NSString to store the value. The above will get the Artist and Track info of the currently playing song.
This is the case for the standard metadata send by a shoutcast or icecast stream.
(can't say for others because I haven't tried them)
Note that each stream may handle and send different metadata.
Since [streamAudioPlayer timedMetadata] is a NSArray you can
NSArray *metaArray = [streamAudioPlayer timedMetadata];
NSLog (@"%i", [metaArray count]); //to see how many elements in the array
MPTimedMetadata *firstMeta = [[streamAudioPlayer timedMetadata] objectAtIndex:0];
Use then the debug console to show the content of metadata using the key, keyspace, timestamp, value properties.
All the above is just an example. There isn't a single way to handle metadata.
Detailed information can be found at
https://developer.apple.com/library/ios/#DOCUMENTATION/MediaPlayer/Reference/MPTimedMetadata_Class/Reference/Reference.html
for the MPTimedMetadata class reference and from there... code on!
timedMetadata
method returns an array with more than oneMPTimedMetadata
instance? Right now I'm using afor-in
loop for getting all of them, but I'm wondering if that's really necessary instead of just using the first element of the array. Thanks! – Knowable