gpt4 book ai didi

iphone - 删除 AVPlayerItem 观察者

转载 作者:行者123 更新时间:2023-12-03 19:21:06 26 4
gpt4 key购买 nike

如果我使用 KVO 来观察我的播放器项目,如下所示:

    AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:url];
[playerItem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:MyClassKVOContext];
[playerItem addObserver:self forKeyPath:@"playbackBufferEmpty" options:NSKeyValueObservingOptionNew context:MyClassKVOContext];
[playerItem addObserver:self forKeyPath:@"playbackLikelyToKeepUp" options:NSKeyValueObservingOptionNew context:MyClassKVOContext];
[playerItem addObserver:self forKeyPath:@"loadedTimeRanges" options:NSKeyValueObservingOptionNew context:MyClassKVOContext];

两个问题:

1) 项目播放完毕后,我是否需要删除我的观察者? (即在 AVPlayerItemDidPlayToEndTimeNotification 中)

2) 如果我调用 [_avQueuePlayer removeAllItems] 是否也会删除每个项目的观察者?

最佳答案

全局创建你的播放器对象(AVPlayerItem *playerItem)并设置其属性并合成它。

1) 项目播放完毕后,我是否需要删除我的观察者? (即在 AVPlayerItemDidPlayToEndTimeNotification 中)

Yes, your need to remove all observer when you are about to leave that view controller where that player is playing. Not after finishes playing.

2) 如果我调用 [_avQueuePlayer removeAllItems] 它是否也会删除每个项目的观察者?

Yes, it remove all observer that are set for that global variable.

关于iphone - 删除 AVPlayerItem 观察者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25729320/

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