現在、AVQueuePlayerでいくつかの.aifファイルを順番に再生しています。各オーディオを通過するときに、その特定のサウンドに関連するアクションを実行したいと思います(たとえば、imageviewのuiimageを変更します)。
私の問題は、NSNotificationを正しく設定することです。キューが最後のオブジェクトで終了したときに通知するように設定しましたが、現在の各アイテムの通知を受信できません。これが私が持っているものです:
//Setting Up My Queue List
yellowVoice = [[AVPlayerItem alloc] initWithURL:[NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/YellowVoice.aif", [[NSBundle mainBundle] resourcePath]]]];
orangeVoice = [[AVPlayerItem alloc] initWithURL:[NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/OrangeVoice.aif", [[NSBundle mainBundle] resourcePath]]]];
redVoice = [[AVPlayerItem alloc] initWithURL:[NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/RedVoice.aif", [[NSBundle mainBundle] resourcePath]]]];
pinkVoice = [[AVPlayerItem alloc] initWithURL:[NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/PinkVoice.aif", [[NSBundle mainBundle] resourcePath]]]];
NSArray *soundEmotions = [NSArray arrayWithObjects:yellowVoice, orangeVoice, redVoice, pinkVoice, nil];
soundQueue = [AVQueuePlayer queuePlayerWithItems:soundEmotions];
// Notify me when queue reaches the end of the last player item
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[soundEmotions lastObject]];
// Notify me when a new player item begins and which one it is
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(currentItemIs:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[soundQueue currentItem]];
[soundQueue play];
nameパラメータで行き詰まっているような気がします。何に変更すればいいですか?また、切り替え時に現在再生中のプレーヤーアイテムの名前を確認するにはどうすればよいですか?ありがとう!
//Here is one of the things I want to do with that info
- (void)currentItemIs:(NSNotification *)notification {
if (soundQueue.currentItem ==yellowVoice) {
UIImage * yellowImage = [UIImage imageNamed:@"yellow.png"];
[UIView transitionWithView:self.view
duration:1.0f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
mainImage.image = yellowImage;
} completion:NULL];
}
if (soundQueue.currentItem ==yellowVoice) {
UIImage * orangeImage = [UIImage imageNamed:@"orange.png"];
[UIView transitionWithView:self.view
duration:1.0f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
mainImage.image = orangeImage;
} completion:NULL];
}
}