0

I use MPMoviePlayerController to stream audio. I also use its timedMetadata property to get the ID3 tag of the mp3 song. This works just fine in iOS 4.x but not in iOS 5.

Here is the piece of code the I use:

MPMoviePlayerController* streamPlayer;    
// allocation and initialization code ...

- (void) metadataUpdate: (id) sender {
NSLog(@"GOT METADATA!!!!!");
if ([streamPlayer timedMetadata]!=nil && [[streamPlayer timedMetadata] count] > 0) {
    NSLog(@"metadata count = %d", [[streamPlayer timedMetadata] count]);
    for (MPTimedMetadata *metadata in [streamPlayer timedMetadata]) {
        NSLog(@"description %@", metadata.allMetadata);
        if ([[metadata.allMetadata valueForKey:@"key"] isEqualToString:@"title"]) {
            song.text = [metadata.allMetadata valueForKey:@"value"];
            filename = song.text;
        }
    }
}

} 

More specifically, under iOS 5 the metadata.allMetadata returns blank in the above code while the [[streamPlayer timedMetadata] count] is 2.

is this a bug in iOS 5?

RawMean
  • 8,374
  • 6
  • 55
  • 82

2 Answers2

2

I'm seeing the same behavior and will file a bug report. In the meantime I'm just building my own dictionary to pass along.

- (void)metadataUpdate:(NSNotification *)notification  
{
    NSMutableDictionary *metaDict = [NSMutableDictionary dictionary];

    if ([self.moviePlayer timedMetadata]!=nil && [[self.moviePlayer timedMetadata] count] > 0) 
    {
        for (MPTimedMetadata *metadata in [self.moviePlayer timedMetadata]) 
        {
            [metaDict setObject:[metadata valueForKey:@"value"] forKey:[metadata valueForKey:@"key"]];
        }
        NSLog(@"Meta value:%@", metaDict);
    }
}

EDIT: In response to the playableDuration issue, the below returns the playableDuration for me. Note however that this is NOT the total time of the video... just what's playable at the moment, which changes depending on what's been downloaded. (in the case of HTTP Live Streaming)

- (void)viewDidLoad
{
    _moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:<your URL>];

    [self.moviePlayer.view setFrame: self.movieView.bounds];
    [self.movieView addSubview: self.moviePlayer.view];

    self.moviePlayer.shouldAutoplay = NO;
    [self.moviePlayer prepareToPlay];

}

- (IBAction)playGame:(UIButton *)sender
{
    if (self.moviePlayer.isPreparedToPlay) {
        [self.moviePlayer play];
        NSLog(@"%f", self.moviePlayer.playableDuration);
    }
}
GnarlyDog
  • 1,247
  • 1
  • 17
  • 24
  • Thanks Chris. Do you also see the problem with playableDuration always returning zero in iOS 5.x? http://stackoverflow.com/questions/7763200/playableduration-returns-0-in-ios5#comment10112948_7763200 – RawMean Apr 08 '12 at 02:31
  • If I check playableDuration at viewDidLoad then YES. But of course... the file isn't loaded yet. If I check the playableDuration after the first segment is loaded, then I get a valid duration time. However for the allMetadata property, I couldn't get anything other than null, even when FOR SURE there is something there.In fact, the above code returns the dictionary that I believe the allMetadata property is suppose to return. But if I run this side by side with the allMetadata property, this returns metadata and the property returns NULL. – GnarlyDog Apr 09 '12 at 00:24
  • I would appreciate it very much if you can share a sample code that shows playableDuration returns anything but zero in iOS 5.x. Perhaps you can provide te staple code in answer to the link above? – RawMean Apr 09 '12 at 04:37
  • No problem. I just updated the code that I use to get the durations as a float (technically its an NSTimeInterval which is a double) – GnarlyDog Apr 09 '12 at 19:53
  • I replicated your code, but I still get zero for playableDuration. I even check the playableDuration periodically (using a timer) and it is zero. There is nothing wrong with the URL either because the stream starts playing after a ~2 seconds. – RawMean May 02 '12 at 05:59
  • How about posting some of your code? Also, this is really a separate issue than the one for which this question was posted. Why not start a new question? It would probably get more visibility that way. If you do, respond here and let me know the question title so I can follow it and help out as well. Again, this worked for me using the 5.0 sdk with the above code, so I do think theres a solution. – GnarlyDog May 05 '12 at 01:00
  • Chris, I had also posted the issue w/ playableDuration as a separate questions. The link is in the first comment above. Thanks again. – RawMean May 05 '12 at 04:50
  • Oh sorry... I'll check it out. – GnarlyDog May 05 '12 at 18:27
1

Found the problem: The allMetadata property of MPTimedMetadata is the culprit. For some reason, this property returns empty in iOS 5 whereas in iOS 4 it works as described in the documentation.
The correct code that worked for me is this:

- (void) metadataUpdate: (id) sender {
  NSLog(@"GOT METADATA!!!!!");
  if ([streamPlayer timedMetadata]!=nil && [[streamPlayer timedMetadata] count] > 0) {
    for (MPTimedMetadata *metadata in [streamPlayer timedMetadata]) {
        if ([[metadata valueForKey:@"key"] isEqualToString:@"title"]) {
            song.text = [metadata valueForKey:@"value"];
            filename = song.text;
        }
    }
  }
} 
RawMean
  • 8,374
  • 6
  • 55
  • 82