简体   繁体   English

使用AVAUDIOPLAYER从音频流中获取元数据

[英]Get Metadata from audio stream with AVAUDIOPLAYER

I would like to retrieve metadata (song, artist) from an audio stream with AVAUDIOPLAYER. 我想使用AVAUDIOPLAYER从音频流中检索元数据(歌曲,艺术家)。 I tried with this code, but i dont get any data from multiple URL. 我尝试使用此代码,但没有从多个URL获取任何数据。

NSURL *url = [NSURL URLWithString:urlString];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];

for (NSString *format in [asset availableMetadataFormats])

Coud someone help me? 库德有人帮我吗? maybe i did wrong? 也许我做错了吗? AVAUDIOPLAYER is available to do that? AVAUDIOPLAYER可以做到吗?

Thanks 谢谢

Here is an example of how to create an AVAsset and use it to create an AVPlayerItem which can then be associated with an instance of AVPlayer . 这是如何创建AVAsset并使用它创建AVPlayerItem的示例,然后可以将其与AVPlayer实例相关联。 Metadata can be retrieved by using properties of the AVAsset ... 可以使用AVAsset属性来检索元数据。

var player = AVPlayer()      
func createAssetAndItem(){

    //create AVAsset from an NSURL. metadata can be retrieved from the asset depending on what is available
let createdAVAsset = AVURLAsset(URL: songNSURL)

    //create an AVPlayerItem from the AVAsset
let createdAVItem = AVPlayerItem(asset: createdAVAsset)

    //asscoaite AVPlayerItem with instance of AVPlayer
player = AVPlayer(AVPlayerItem: createdAVItem)


}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM