ios - AVPlayer 的定时元数据

标签 ios swift avplayer

你能控制AVURLAsset加载它需要的数据的方式吗?我需要添加自定义 HTTP header (ICY-MetaData=1),但似乎不知道如何操作。

最佳答案

显然,AVPlayer 会自动从 Icecast 请求元数据。下面的代码完美运行。

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.
    }
}

关于ios - AVPlayer 的定时元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27955125/

相关文章:

ios - 无法在 currentRunLoop only MainRunLoop 上安排 NSStream

swift - AVPlayer addObserver 永远不会被调用

ios - 登录 SFAuthenticationSession 然后在 SFSafariViewController 中打开一个执行 SSO 的链接

ios - 更改色调颜色以通过 iOS 中的 Notes 应用程序共享

ios - 按比例缩放 UIPanGesture 操作以缩放 SpriteKit 场景中的级别

ios - 为什么我们需要将 sqlite DB 文件移动到文档文件夹?我们可以从 bundle 访问并对其执行数据库操作吗?

ios - 持续时间不随 AVPlayer currentItem 一起提供

ios - 使用 AVPlayer 获取 AirPlay 设备的名称

ios - 无法访问 UITableViewCell 中 UIView 的图层属性

swift - 每次编译测试目标时运行单元测试