永远不会调用AVPlayer addObserver

时间:2017-01-26 10:50:01

标签: swift avplayer

我正在尝试获取AVPlayer timedMetadata,但永远不会调用观察者

self.metaItem!.addObserver(self, forKeyPath: "metaData", options: NSKeyValueObservingOptions(), context: nil)
        metPlayer=AVPlayer(playerItem: metaItem)
        metPlayer.play()
...

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change:
        [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
        if keyPath != "metaData" { return }
        print("...")
    }

但MPMoviePlayerController工作正常

感谢。

1 个答案:

答案 0 :(得分:1)

metaItem AVPlayerItem应该观察关键路径 timedMetadata ,但不是" metaData"

self.metaItem!.addObserver(self, forKeyPath: "timedMetadata", options: NSKeyValueObservingOptions(), context: nil)