简体   繁体   English

从流中获取元数据有问题吗?

[英]Issue getting metadata from stream?

I am trying to obtain the metadata such as Artist name / Track name for my URL, however I don't see, to be getting it at all, I am not quite sure what I am missing, the audio loads up and plays just fine: 我正在尝试获取URL的元数据,例如艺术家名称/曲目名称,但是我完全看不到,我不确定我丢失了什么,音频加载并正常播放了:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.mainTitle.text = _stationName;

    NSString *u = @"http://pub1.sky.fm:80/sky_solopiano";

    NSURL *url = [NSURL URLWithString:u];

    radiosound = [[AVPlayer alloc] initWithURL:url];

    [radiosound play];

}

-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
    AVPlayerItem * item = (AVPlayerItem*)object;
    NSLog(@"%@", item.timedMetadata);


}

Update Per the suggestion of a member in this question, I tried implementing 更新根据这个问题中成员的建议,我尝试实施

AVAsset *info = radiosound.currentItem.asset;

    NSLog(@"%@",info);

Instead of 代替

-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
        AVPlayerItem * item = (AVPlayerItem*)object;
        NSLog(@"%@", item.timedMetadata);


    }

But this only returns data that I already know and does not refresh, it currently returns: 但这只会返回我已经知道并且不会刷新的数据,它当前会返回:

<AVURLAsset: 0x109c7ccf0, URL = http://pub1.sky.fm:80/sky_solopiano>

You've overridden/implemented the observer hook on NSObject, however you didn't set up property observing for the AVPlayer anywhere, so this method will never fire. 您已经重写/实现了NSObject上的观察者挂钩,但是您没有在任何地方设置对AVPlayer的属性观察,因此该方法永远不会触发。

I think what you're actually interested in is: 我认为您真正感兴趣的是:

radiosound.currentItem.asset

. . . which you can use immediately after you've alloc/init'd your radiosound instance. 您可以在分配/初始化您的无线电声音实例后立即使用。

The available properties on this class are here 此类的可用属性在这里

To obtain docs for a given class: 要获取给定类的文档:

  • Google the class name - it will almost always return results. Google的班级名称-它几乎总是会返回结果。
  • Option-click the class in Xcode 按住Option键单击Xco​​de中的类
  • Use a documentation browser like Dash 使用文档浏览器(如Dash)

Key-value observing (KVO) 键值观察(KVO)

You probably don't need KVO in this case, however its something you should definitely check up on. 在这种情况下,您可能不需要KVO,但是您绝对应该检查一下。 For more information there are the Apple docs, as well as loads of tutorials. 有关更多信息,请参阅Apple文档以及大量教程。 Perhaps this one ? 也许这一个

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

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