是否可以在iPhone SDK中使用HTTP实时流读取元数据 [英] is it possible to read metadata using HTTP live streaming in the iPhone SDK

查看:88
本文介绍了是否可以在iPhone SDK中使用HTTP实时流读取元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用HTTP Live Streaming方法播放实时流时,是否可以读取当前的元数据(例如,标题和艺术家)?这是用于iPhone广播应用程序的.

When playing a live stream using the HTTP Live Streaming method, is it possible read the current metadata (eg. Title and Artist)? This is for an iPhone radio app.

推荐答案

不确定该问题对其作者仍然适用,但是可能会有所帮助.经过两天的痛苦,我调查了这很简单.这是对我有用的代码:

Not sure that this question is still actual for its author, but may be it will help someone. After two days of pain I investigated that it's quite simple. Here is the code that works for me:

AVPlayerItem* playerItem = [AVPlayerItem playerItemWithURL:[NSURL URLWithString:<here your http stream url>]];

[playerItem addObserver:self forKeyPath:@"timedMetadata" options:NSKeyValueObservingOptionNew context:nil];

AVPlayer* player = [[AVPlayer playerWithPlayerItem:playerItem] retain];
[player play];

然后:

- (void) observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object
                        change:(NSDictionary*)change context:(void*)context {

   if ([keyPath isEqualToString:@"timedMetadata"])
   {
      AVPlayerItem* playerItem = object;

      for (AVMetadataItem* metadata in playerItem.timedMetadata)
      {
         NSLog(@"\nkey: %@\nkeySpace: %@\ncommonKey: %@\nvalue: %@", [metadata.key description], metadata.keySpace, metadata.commonKey, metadata.stringValue);
      }
   }
}

就是这样.我不知道为什么苹果公司没有在AVPlayerItem的文档中提供此示例以访问流的标题",这是现实世界中流音频的关键功能.在"AV Foundation框架参考"中,他们在任何需要的地方都没有提及"timedMetadata".而且Matt的示例不适用于所有流(但AVPlayer可以).

That's it. I dont know why Apple didn't provide in the docs for AVPlayerItem this sample for access "title" of the stream which is the key feature for real world streaming audio. In "AV Foundation Framework Reference" they tell about "timedMetadata" nowhere where needed. And Matt's sample does not work with all streams (but AVPlayer does).

这篇关于是否可以在iPhone SDK中使用HTTP实时流读取元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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