Getting metadata from an audio stream
Asked Answered
I

2

13

I would like to get the file name and, if possible, album image from a streaming URL in a AVPlayerItem that I am playing with AVQueuePlayer but I don't know how to go about doing this.

Also if it turns out that my streaming URL doesn't have any metadata can I put metadata in my NSURL* before passing it to the AVPlayerItem?

Thanks.

Insurgent answered 10/10, 2011 at 0:24 Comment(3)
I use the Dropbox API to get the stream URLInsurgent
audio yes. but I think it doesn't matter if it is audio or video. They are both handled by the same AVPlayerItemInsurgent
#44535965 Help me Thank you in advanced....Aggrieved
I
39

Well I am surprised no one has answered this question. In fact no one has answered any of my other questions. Makes me wonder how much knowledge people in here truly have.

Anyways, I will go ahead and answer my own question. I found out how to get the metadata by doing the following:

AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:url];
NSArray *metadataList = [playerItem.asset commonMetadata];
for (AVMetadataItem *metaItem in metadataList) {
    NSLog(@"%@",[metaItem commonKey]);
}

Which gives me a list as follows:

title
creationDate
artwork
albumName
artist

With that list now I know how to access the metadata from my audio stream. Just simply go through the NSArray and look for an AVMetadataItem that has the commonKey that I want (for example, title). Then when I find the AVMetadataItem just get the value property from it.

Now, this works great but it may be possible that when you try to get the data it will take a while. You can load the data asynchronously by sending loadValuesAsynchronouslyForKeys:completionHandler: to the AVMetadataItem you just found.

Hope that helps to anyone who may find themselves with the same problem.

Insurgent answered 20/10, 2011 at 5:5 Comment(2)
for some reason my commond metadata is 0 value. Whereas timedmetadata has one value ["title"]Burleigh
Good work on doing your own research and finding an answer. Kudos :)Soprano
T
2

When retrieving a particular item I would use the Metadata common keys constant declared in AVMetadataFormat.h, i.e.: AVMetadataCommonKeyTitle.

NSUInteger titleIndex = [avItem.asset.commonMetadata indexOfObjectPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
    AVMutableMetadataItem *metaItem = (AVMutableMetadataItem *)obj;
    if ([metaItem.commonKey isEqualToString:AVMetadataCommonKeyTitle]) {
        return YES;
    }
    return NO;
}];

AVMutableMetadataItem *item = [avItem.asset.commonMetadata objectAtIndex:titleIndex];
NSString *title = (NSString *)item.value;
Triplicity answered 9/4, 2014 at 15:14 Comment(1)
#44535965 Help me Thank you in advanced....Aggrieved

© 2022 - 2024 — McMap. All rights reserved.