2011-12-17 57 views
2

我使用了AvQueuePlayer在後臺播放音頻。爲了讓AvQueuePlayer的播放列表不爲空,我使用鍵值觀察來關注AvQueuePlayer的當前項目以準備加載下一個播放項目。有時它運作良好,但有時會失敗。AVPlayer密鑰值的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的類引用擡頭。然後我發現有人說,財產「地位」可以被觀察到,但它並沒有提到當前的項目。但我發現有些人使用屬性currentItem作爲可觀察的。我現在完全困惑。請幫幫我。

回答

0

我有同樣的問題,想知道一首AVQueuePlayer中的歌曲何時完成。我最終這樣做,似乎更安全。

[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(songFinishedWithNotification:) 
              name:AVPlayerItemDidPlayToEndTimeNotification 
              object:nil]; 
相關問題