我想在我的应用中使用AVAudioPlayer。逻辑是:首先同时播放一组声音,然后播放另一组声音。但我发现应用程序只能将所有这些设置一起播放,不能逐个播放。比较新的,我发现它是难以理解,有人有想法吗?感谢您的帮助和想法。
答案 0 :(得分:1)
使用委托方法识别完第一首歌曲然后在该方法中开始新歌。
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
{
//play next song from List/Array of songs.
}
播放歌曲AVAudioPlayer代码如下所示。
NSString* filename = [soundsList objectAtIndex:YOURINDEXNUMBER];
NSString *path = [[NSBundle mainBundle] pathForResource:filename ofType:@"mp3"];
AVAudioPlayer * newAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
self.theAudio = newAudio; // automatically retain audio and dealloc old file if new file is loaded
[newAudio release]; // release the audio safely
theAudio.delegate = self;
[theAudio prepareToPlay];
[theAudio setNumberOfLoops:0];
[theAudio play];