AVPlayer的currentItem键值是否可观察?
我使用 AvQueuePlayer 在后台播放音频。为了保持 AvQueuePlayer 的播放列表不为空,我使用键值观察来监视 AvQueuePlayer 的 currentItem ,以便准备加载下一个播放项目。有时效果很好,但有时却失败。
这是我收到的崩溃报告:
Date/Time: 2011-12-16 23:43:58.963 +0800
OS Version: iPhone OS 4.3.5 (8L1)
Report Version: 104
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x4f2ecfe8
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x32f0aca4 objc_msgSend + 28
1 Foundation 0x3165386c NSKVONotify + 24
2 Foundation 0x31651bb0 -[NSKeyValueObservance observeValueForKeyPath:ofObject:change:context:] + 220
3 Foundation 0x315fa7ea NSKeyValueNotifyObserver + 210
4 Foundation 0x315fa492 NSKeyValueDidChange + 230
5 Foundation 0x315e666a - [NSObject(NSKeyValueObserverNotification) didChangeValueForKey:] + 70
6 AVFoundation 0x33f190f2 -[AVPlayerItem didChangeValueForKey:] + 26
7 AVFoundation 0x33f1ceba __avplayeritem_fpItemNotificationCallback_block_invoke_1 + 2310
8 libdispatch.dylib 0x338da8e0 _dispatch_call_block_and_release + 4
9 libdispatch.dylib 0x338d61ee _dispatch_main_queue_callback_4CF$VARIANT$up + 306
10 CoreFoundation 0x34c1d934 __CFRunLoopRun + 1328
11 CoreFoundation 0x34badebc CFRunLoopRunSpecific + 224
12 CoreFoundation 0x34baddc4 CFRunLoopRunInMode + 52
13 GraphicsServices 0x33e5e418 GSEventRunModal + 108
14 GraphicsServices 0x33e5e4c4 GSEventRun + 56
15 UIKit 0x31272d62 -[UIApplication _run] + 398
16 UIKit 0x31270800 UIApplicationMain + 664
17 WeatherTunes 0x0004b31e main (main.m:17)
18 WeatherTunes 0x0004b2ac start + 32
这是我如何使用键值观察:
[_queuePlayer addObserver:self forKeyPath:@"currentItem" options:NSKeyValueObservingOptionNew context:nil];
[_queuePlayer addObserver:self forKeyPath:@"currentItem.status" options:NSKeyValueObservingOptionNew context:nil];
我在 AvPlayer 的类参考中查找。然后我发现据说属性“status”可以被观察,但没有提到currentItem。但我发现有些人使用 currentItem 属性作为可观察的。我现在完全困惑了。请帮我。
I used a AvQueuePlayer for playing audio in background. And to keep the playlist of AvQueuePlayer not empty, I used key-value observing to keep an eye on the currentItem of AvQueuePlayer for getting ready to load a next play item. Sometimes it works well, but sometimes it failes.
Here is the crash report I received:
Date/Time: 2011-12-16 23:43:58.963 +0800
OS Version: iPhone OS 4.3.5 (8L1)
Report Version: 104
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x4f2ecfe8
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x32f0aca4 objc_msgSend + 28
1 Foundation 0x3165386c NSKVONotify + 24
2 Foundation 0x31651bb0 -[NSKeyValueObservance observeValueForKeyPath:ofObject:change:context:] + 220
3 Foundation 0x315fa7ea NSKeyValueNotifyObserver + 210
4 Foundation 0x315fa492 NSKeyValueDidChange + 230
5 Foundation 0x315e666a - [NSObject(NSKeyValueObserverNotification) didChangeValueForKey:] + 70
6 AVFoundation 0x33f190f2 -[AVPlayerItem didChangeValueForKey:] + 26
7 AVFoundation 0x33f1ceba __avplayeritem_fpItemNotificationCallback_block_invoke_1 + 2310
8 libdispatch.dylib 0x338da8e0 _dispatch_call_block_and_release + 4
9 libdispatch.dylib 0x338d61ee _dispatch_main_queue_callback_4CF$VARIANT$up + 306
10 CoreFoundation 0x34c1d934 __CFRunLoopRun + 1328
11 CoreFoundation 0x34badebc CFRunLoopRunSpecific + 224
12 CoreFoundation 0x34baddc4 CFRunLoopRunInMode + 52
13 GraphicsServices 0x33e5e418 GSEventRunModal + 108
14 GraphicsServices 0x33e5e4c4 GSEventRun + 56
15 UIKit 0x31272d62 -[UIApplication _run] + 398
16 UIKit 0x31270800 UIApplicationMain + 664
17 WeatherTunes 0x0004b31e main (main.m:17)
18 WeatherTunes 0x0004b2ac start + 32
And here is how I use key-value observing:
[_queuePlayer addObserver:self forKeyPath:@"currentItem" options:NSKeyValueObservingOptionNew context:nil];
[_queuePlayer addObserver:self forKeyPath:@"currentItem.status" options:NSKeyValueObservingOptionNew context:nil];
And I looked up in the class reference of AvPlayer. Then I found that it was said the property "status" could be observable while it did not mention the currentItem. But I found some people use the property currentItem as observable. I am totally confused now. Please help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了同样的问题,想知道 AVQueuePlayer 中的歌曲何时完成。我最终还是这样做了,看起来更安全。
I had the same problem, wanted to know when a song in an AVQueuePlayer finished. I ended up doing this instead, seemed safer.