user2174560
user2174560

Reputation: 139

Getting metadata from a radio stream using MPMoviePlayer? (iOS)

I am using MPMoviePlayer for radio streaming and i need to get the current track info.

Can anyone help me as to how I can do this?

Upvotes: 0

Views: 800

Answers (1)

dsgriffin
dsgriffin

Reputation: 68596

Firstly, you need to set a NSNotification so that you can get the data at specific intervals, like so:

[[NSNotificationCenter defaultCenter] addObserver:self
                                      selector:@selector(StreamMeta:)
                                      name:MPMoviePlayerTimedMetadataUpdatedNotification
                                      object:nil];

Next, you create the method. I am going to use streamMPMoviePlayer as the name of your MPMoviePlayerController and metaString as the NSString which will store the metadata values:

- (void)StreamMeta:(NSNotification*)notification
{
  if ([streamMPMoviePlayer timedMetadata] != nil) {
      MPTimedMetadata *meta = [[streamMPMoviePlayer timedMetadata] objectAtIndex:0];
      metaString = meta.value; // gives the NSString the artist/song information
  }
  else {
     // No metadata available
  }
}

Upvotes: 1

Related Questions