从音频流中获取元数据 [英] Getting metadata from an audio stream

查看:202
本文介绍了从音频流中获取元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取文件名,如果可能的话,从AVPlayerItem中的流媒体网址获取专辑图片,我正在玩AVQueuePlayer,但我不知道如何去做。

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.

如果事实证明我的流媒体网址没有任何元数据,我可以将元数据放入 NSURL * 在将它传递给AVPlayerItem之前?

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?

谢谢。

推荐答案

我很惊讶没有人回答这个问题。
事实上,没有人回答我的任何其他问题。
让我想知道这里的人们真正拥有多少知识。

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

现在有了这个列表,我知道如何从我的音频流中访问元数据。只需简单地浏览 NSArray 并查找具有 commonKey AVMetadataItem c $ c>我想要的(例如, title )。然后,当我找到 AVMetadataItem 时,只需从中获取属性。

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.

现在,这很有效但是当你试图获取数据时可能需要一段时间。您可以通过将 loadValuesAsynchronouslyForKeys:completionHandler:发送到您刚刚找到的 AVMetadataItem 来异步加载数据。

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.

这篇关于从音频流中获取元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆