gpt4 book ai didi

swift - 在 Swift 2 Xcode 7 中从 .pls 接收元数据

转载 作者:行者123 更新时间:2023-11-30 13:55:39 25 4
gpt4 key购买 nike

我正在编写一个广播应用程序,想要从 .pls 格式的 url 和以下代码获取元数据:

var PlayerItem: AVPlayerItem!
var asset : AVAsset? // init with url of .pls format

PlayerItem = AVPlayerItem(asset: asset!)
PlayerItem.addObserver(self, forKeyPath: "timedMetadata" [...]

PlayerItem.timedMetadata - is always nil or 0

我应该添加什么来接收元数据?

最佳答案

快速 Swift 2 实现:

var player: AVPlayer!
var playerItem: AVPlayerItem!

override func viewDidLoad() {
super.viewDidLoad()
....
playerItem = AVPlayerItem(URL: NSURL(string: <streamURL>)!)
player = AVPlayer(playerItem: playerItem)

// To be informed when metadata changes
playerItem.addObserver(self, forKeyPath: "timedMetadata", options: [], context: nil)
}

override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
// Get medatata, making sure to support a wider range of characters
let origMetaTitle = (playerItem.timedMetadata?.first?.stringValue?.dataUsingEncoding(NSISOLatin1StringEncoding, allowLossyConversion: true))!
let convertedMetaTitle = String(data: origMeta, encoding: NSUTF8StringEncoding)!
....
}

deinit {
// Be a good citizen
playerItem.removeObserver(self, forKeyPath: "timedMetadata")
}

关于swift - 在 Swift 2 Xcode 7 中从 .pls 接收元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33660736/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com