3

現在、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];


    }


}
4

2 に答える 2

3
- (void)currentItemIs:(NSNotification *)notification 
{
   AVPlayerItem *p = [notification object];
   if (p ==yellowVoice) {
   //rest of the code
   }
}
于 2013-03-12T11:01:12.620 に答える
2

ブーシャンの答えには、各アイテムの通知をトリガーするループがありません。

for (AVPlayerItem *playerItem in queuePlayer.items) {
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(currentItemIs:)  name:AVPlayerItemDidPlayToEndTimeNotification object:playerItem];
        }
于 2015-03-04T13:12:07.453 に答える