我正在尝试为我的 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);
}
更新根据这个问题中成员的建议,我尝试实施
AVAsset *info = radiosound.currentItem.asset;
NSLog(@"%@",info);
代替
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
AVPlayerItem * item = (AVPlayerItem*)object;
NSLog(@"%@", item.timedMetadata);
}
但这只会返回我已经知道的数据并且不会刷新,它当前返回:
<AVURLAsset: 0x109c7ccf0, URL = http://pub1.sky.fm:80/sky_solopiano>