0

サウンドの再生が終了した後にコードを実行しようとしていますが、それを実行するための最良の方法がわかりません。私はそれを見てきましたperformSelectorOnMainThread....が、完全には理解していません-それでも、それが問題に取り組むための最良の方法であるかどうかはわかりません。サウンドの再生が終了した後、ラベルのテキストの色を変更したい。助けていただければ幸いです。私のコードは以下の通りです:

-(void) playWordSound:(UILabel *)label
{
    NSString *path;
    SystemSoundID soundId;
    switch (label.tag)
    {
        case 1:
            path = [[NSBundle mainBundle] pathForResource:@"humpty" ofType:@"wav"];
            break;
        case 2:
            path = [[NSBundle mainBundle] pathForResource:@"dumpty" ofType:@"wav"];
            break;
        case 3:
            path = [[NSBundle mainBundle] pathForResource:@"saty" ofType:@"wav"];
            break;
        case 4:
            path = [[NSBundle mainBundle] pathForResource:@"on 2" ofType:@"wav"];
            break;
        case 5:
            path = [[NSBundle mainBundle] pathForResource:@"a 3" ofType:@"wav"];
            break;
        case 6:
            path = [[NSBundle mainBundle] pathForResource:@"wall" ofType:@"wav"];
            break;
    }
        NSURL *url = [NSURL fileURLWithPath:path];
        AudioServicesCreateSystemSoundID( (CFURLRef)objc_unretainedPointer(url), &soundId);
    AudioServicesPlaySystemSound(soundId); 
    //this is where i want to change the color of the label
}
4

2 に答える 2

2

AVPlayerItemを使用して、イベントAVPlayerItemDidPlayToEndTimeNotificationのオブザーバーを追加します。

例えば

..。

AVPlayerItem* playerItem = [AVPlayerItem playerItemWithAsset:asset];
[playerItem addObserver:self forKeyPath:@"status" options:0 context:&ItemStatusContext];
[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(playerItemDidReachEnd:)
                                             name:AVPlayerItemDidPlayToEndTimeNotification
                                             object:playerItem];
player = [AVQueuePlayer playerWithPlayerItem:playerItem];
[player play];

..。

- (void)playerItemDidReachEnd:(NSNotification *)notification {
    // Do stuff here
}

...。

于 2012-05-15T16:18:05.850 に答える
0

この方法はあなたを助けるかもしれません:

OSStatus AudioServicesAddSystemSoundCompletion (
   SystemSoundID                           inSystemSoundID,
   CFRunLoopRef                            inRunLoop,
   CFStringRef                             inRunLoopMode,
   AudioServicesSystemSoundCompletionProc  inCompletionRoutine,
   void                                    *inClientData
);
于 2012-05-15T16:15:02.200 に答える