0

I add a observer named 'status' into AVPlayerItem. Send the observer then set AVPlayerItem to nil when the observer does not complete

I have remove the observer when dealloc AVPlayerItem

Get the following error:

NSInternalInconsistencyException', reason: 'An instance 0x7dc5e7d0 of class AVPlayerItem was deallocated while key value observers were still registered with it. Current observation info: ( Context: 0x0, Property: 0x7b8ad140>

4

3 回答 3

1

我不认为AVPlayerItem应该观察任何事情,如果没有具体的例子,就你的情况很难说。通常,此流程是您的控制器成为来自AVPlayerItem.

例如:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(movieItemDidReachEnd:)
                                             name:AVPlayerItemDidPlayToEndTimeNotification
                                           object:nil];

然后当你完成后(即当你将 AVPlayerItem 设置为 时nil),你删除观察者:

[[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemDidPlayToEndTimeNotification object:nil];

如果您提供更多详细信息,也许我可以提供更多帮助。谢谢!

编辑:

很快就会...

    NSNotificationCenter.defaultCenter().addObserver(self, selector: "movieDidReachEnd", name: AVPlayerItemDidPlayToEndTimeNotification, object: nil)

    NSNotificationCenter.defaultCenter().removeObserver(self, name: AVPlayerItemDidPlayToEndTimeNotification, object: nil)
于 2015-12-04T06:34:19.007 回答
0

它通过异步导致初始 avplayeritem

于 2015-12-04T07:36:28.093 回答
0

在将 playerItem 设置为 nil 之前,删除观察者:

playerItem.removeObserver(self, forKeyPath: "status")

如果你等到 deinit/dealloc,在你已经将 playerItem 设置为 nil 之后,那么你将不再引用它来删除观察者。

于 2015-12-04T06:32:16.717 回答