san*_*san 8 objective-c key-value-observing ios avplayer
我试图抓住一个AVPlayer无法继续播放的时刻,以防没有更多媒体可用(网络太慢,信号丢失等).如文档和不同的示例中所述,我正在使用它KVO来检测:
item = [[AVPlayerItem alloc] initWithURL:audioURL];
player = [AVPlayer playerWithPlayerItem:item];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onItemNotification:) name:AVPlayerItemPlaybackStalledNotification object:item];
[item addObserver:self forKeyPath:@"playbackBufferEmpty" options:NSKeyValueObservingOptionNew context:nil];
[item addObserver:self forKeyPath:@"playbackLikelyToKeepUp" options:NSKeyValueObservingOptionNew context:nil];
...
- (void) onItemNotification:(NSNotification*)not
{
NSLog(@"Item notification: %@", not.name);
}
...
- (void) observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary*)change context:(void*)context
{
NSLog(@"Observe keyPath %@", keyPath);
}
Run Code Online (Sandbox Code Playgroud)
我正在开始播放并WiFi在此之后关闭.不幸的是,playbackBufferEmpty"也没有AVPlayerItemPlaybackStalledNotification"来了.在播放停止的那一刻,我只收到一个AVPlayerItemTimeJumpedNotification,就是全部.但是,当我收到这些通知时,至少有2次.但我无法弄清楚每次播放停止时如何获取它们.难道我做错了什么?
| 归档时间: |
|
| 查看次数: |
6445 次 |
| 最近记录: |