本文介绍了使用AVPlayer定时元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你能控制 AVURLAsset
如何加载它需要的数据?我需要添加一个自定义HTTP标头( ICY-MetaData = 1
)并且似乎无法弄清楚如何。
Can you control how AVURLAsset
loads the data it requires? I need to add a custom HTTP header (ICY-MetaData=1
) and can't seem to figure out how.
推荐答案
显然, AVPlayer
会自动从Icecast请求元数据。下面的代码工作正常。
Apparently, AVPlayer
automatically requests metadata from Icecast. The code below works perfectly.
class ViewController: UIViewController {
var Player: AVPlayer!
var PlayerItem: AVPlayerItem!
override func viewDidLoad() {
super.viewDidLoad()
PlayerItem = AVPlayerItem(URL: NSURL(string: "http://live.machine.fm/aac"))
PlayerItem.addObserver(self, forKeyPath: "timedMetadata", options: nil, context: nil)
Player = AVPlayer(playerItem: PlayerItem)
Player.play()
}
override func observeValueForKeyPath(keyPath: String, ofObject object: AnyObject, change: [NSObject : AnyObject], context: UnsafeMutablePointer<Void>) -> Void {
if keyPath != "timedMetadata" { return }
var data: AVPlayerItem = object as AVPlayerItem
for item in data.timedMetadata as [AVMetadataItem] {
println(item.value)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
这篇关于使用AVPlayer定时元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!