2010-04-01 134 views
1

AVAudioPlayer * myExampleSound;如何播放音樂,以便在結束後自動播放音樂?

NSString *myExamplePath = [[NSBundle mainBundle] pathForResource:@"myaudiofile" ofType:@"caf"]; 

myExampleSound =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:myExamplePath] error:NULL]; 

myExampleSound.delegate = self; 

[myExampleSound play]; 

如何播放myExampleSound,使其在結束後自動重播? 我正在使用上面的代碼。

請人幫忙。

回答

1

的AVAudioPlayerDelegate得到了一個方法

- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag 

聲音播放完畢後調用。您必須實施此方法,然後才能夠再次播放聲音。