RawMean
RawMean

Reputation: 8717

MPMoviePlayerController timedMetadata returns blank in iOS 5

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?

Upvotes: 0

Views: 1350

Answers (2)

GnarlyDog
GnarlyDog

Reputation: 1247

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);
    }
}

Upvotes: 2

RawMean
RawMean

Reputation: 8717

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;
        }
    }
  }
} 

Upvotes: 1

Related Questions