我希望能够在一个按钮上一个接一个地播放2个单独的声音文件(wav)。我用来玩一个的代码是:
NSString *path = [[NSBundle mainBundle] pathForResource:@"Applause" ofType:@"wav"];
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate = self;
[theAudio play];
你知道如何修改它可以播放2声音,还是我需要创建另一个动作。
感谢您的帮助。
答案 0 :(得分:0)
您可以实施delegate method来开始下一个声音:
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
AVAudioPlayer* theAudio1=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:filePath1] error:NULL];
AVAudioPlayer* theAudio2=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:filePath2] error:NULL];
theAudio1.delegate = self;
[theAudio1 play];
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag {
[theAudio2 play];
}