简体   繁体   English

从MPMoviePlayerController获取元数据

[英]Getting MetaData from MPMoviePlayerController

Ok So i have a Live Stream from a URL using MPMoviePlayerController. 好的,所以我有一个使用MPMoviePlayerController从URL直播的流。

Player = [[MPMoviePlayerController alloc] 
               initWithContentURL:[NSURL URLWithString:@"MY_URL_HERE_I_REMOVED"]];
Player.movieSourceType = MPMovieSourceTypeStreaming

Now The stream gives Meta Data (I believe thats what everyone calls it). 现在,流提供元数据(我相信这就是每个人所说的)。 Eg. 例如。 Name of the track etc. 曲目名称等

I want to get this information and display it on a Label. 我想获取此信息并将其显示在标签上。

I have no idea how to get it, I cant change from MPMoviePlayerController and after searching for hours i found MPTimedMetadata class reference but dunno how to use to get this information. 我不知道如何获取它,我无法从MPMoviePlayerController进行更改,在搜索了几个小时后,我发现了MPTimedMetadata类参考,但不知道如何使用该信息。

Great if you can mention how to use the notification also to trigger every time this data changes. 很棒,如果您能提到每次数据更改时也如何使用通知来触发。

Assuming that you already know what kind of metadata is being sent from the stream (if you don't, use a media player like VLC to see), you must first register a notification to get the metadata in timed intervals and then a method to process them. 假设您已经知道从流中发送了什么样的元数据(如果不知道,则使用VLC之类的媒体播放器进行查看),您必须首先注册一个通知以按时间间隔获取元数据,然后使用一种方法处理它们。

Starting with the notification, just 从通知开始,

 [[NSNotificationCenter defaultCenter] addObserver:self
                                          selector:@selector(MetadataUpdate:)
                                              name:MPMoviePlayerTimedMetadataUpdatedNotification
                                            object:nil];

after the MPMoviePlayerController allocation. 在MPMoviePlayerController分配之后。

Then on the MetadataUpdate method 然后在MetadataUpdate方法上

- (void)MetadataUpdate:(NSNotification*)notification
{
    if ([streamAudioPlayer timedMetadata]!=nil && [[streamAudioPlayer timedMetadata] count] > 0) {
        MPTimedMetadata *firstMeta = [[streamAudioPlayer timedMetadata] objectAtIndex:0];
        metadataInfo = firstMeta.value;
    }
}

where streamAudioplayer is your MPMoviePlayerController and metadataInfo a NSString to store the value. 其中streamAudioplayer是您的MPMoviePlayerController和metadataInfo一个NSString来存储值。 The above will get the Artist and Track info of the currently playing song. 上面将获得当前正在播放的歌曲的艺术家和曲目信息。

This is the case for the standard metadata send by a shoutcast or icecast stream. 广播或冰河流发送的标准元数据就是这种情况。 (can't say for others because I haven't tried them) (不能对其他人说,因为我还没有尝试过)

Note that each stream may handle and send different metadata. 注意,每个流可以处理和发送不同的元数据。 Since [streamAudioPlayer timedMetadata] is a NSArray you can 由于[streamAudioPlayer timedMetadata]是NSArray,因此您可以

NSArray *metaArray = [streamAudioPlayer timedMetadata];
NSLog (@"%i", [metaArray count]); //to see how many elements in the array
MPTimedMetadata *firstMeta = [[streamAudioPlayer timedMetadata] objectAtIndex:0];

Use then the debug console to show the content of metadata using the key, keyspace, timestamp, value properties. 然后,使用调试控制台通过键,键空间,时间戳,值属性显示元数据的内容。

All the above is just an example. 以上只是一个例子。 There isn't a single way to handle metadata. 没有处理元数据的单一方法。 Detailed information can be found at 详细信息请参见

https://developer.apple.com/library/ios/#DOCUMENTATION/MediaPlayer/Reference/MPTimedMetadata_Class/Reference/Reference.html https://developer.apple.com/library/ios/#DOCUMENTATION/MediaPlayer/Reference/MPTimedMetadata_Class/Reference/Reference.html

for the MPTimedMetadata class reference and from there... code on! MPTimedMetadata类参考,然后从那里开始……代码!

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

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