Getting metadata from an audio stream

后端 未结 2 2188
攒了一身酷
攒了一身酷 2021-01-31 06:15

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 doi

2条回答
  •  名媛妹妹
    2021-01-31 06:56

    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.

提交回复
热议问题