我有一个AVQueuePlayer,我是从4个AVPlayerItems的数组创建的,它都可以正常播放.
我希望在队列中的最后一项完成播放时做一些事情,我在这里看了很多答案,这看起来最符合我想要的: 在声音结束后执行代码的最佳方法播放
在我的按钮处理程序中,我有这个代码:
static const NSString *ItemStatusContext;
[thePlayerItemA addObserver:self forKeyPath:@"status" options:0 context:&ItemStatusContext];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd)
name:AVPlayerItemDidPlayToEndTimeNotification
object:thePlayerItemA];
theQueuePlayer = [AVQueuePlayer playerWithPlayerItem:thePlayerItemA];
[theQueuePlayer play];
Run Code Online (Sandbox Code Playgroud)
然后我有一个处理playerItemDidReachEnd的函数:
- (void)playerItemDidReachEnd:(NSNotification *)notification {
// Do stuff here
NSLog(@"IT REACHED THE END");
}
Run Code Online (Sandbox Code Playgroud)
但是当我运行它时,我得到一个内部不一致的例外:
An -observeValueForKeyPath:ofObject:change:context: message was received but not handled.
Key path: status
Observed object: <AVPlayerItem: 0x735a130, asset = <AVURLAsset: 0x73559c0, URL = file://localhost/Users/mike/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/A0DBEC13-2DA6-4887-B29D-B43A78E173B8/Phonics%2001.app/yes.mp3>>
Change: {
kind = 1;
Run Code Online (Sandbox Code Playgroud)
}
我究竟做错了什么?