4

I am looking for some solution to get metadata information from my stream http://vibesradio.org:8002/ to be displayed in UILabel of an app that I am developing.

Thanks in advance.

EmilDo
  • 1,177
  • 3
  • 16
  • 33

1 Answers1

6

Here is the answer, there were some partial answers here at stack, so I submit complete solution:

First in viewDidLoad we need to add observable metadata object:

 [playerItem addObserver:self forKeyPath:@"timedMetadata" options:NSKeyValueObservingOptionNew   context:NULL];

Now, all we need is UILabel and a function in order to display the metadata, assuming that the UIlabel nowPlaying is created, we add the following code:

- (void) observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object
                     change:(NSDictionary*)change context:(void*)context {

if ([keyPath isEqualToString:@"timedMetadata"])
{
    playerItem = object;

    for (AVMetadataItem* metadata in playerItem.timedMetadata)
    {
        NSLog(@"\nkey: %@\nkeySpace: %@\ncommonKey: %@\nvalue: %@", [metadata.key description], metadata.keySpace, metadata.commonKey, metadata.stringValue);
        NSString *edited = [metadata.stringValue stringByReplacingOccurrencesOfString:@"_" withString:@" "];
        self.nowPlaying.text = edited;
    }
  }
}

And thats it, now you should have your stream info displayed.

Matt H
  • 6,422
  • 2
  • 28
  • 32
EmilDo
  • 1,177
  • 3
  • 16
  • 33
  • I just tried this approach, but got the following error `Property 'timedMetadata' not found on object of type 'AVPlayer*'` Any suggestions? – vzm Nov 03 '13 at 16:00