我想播放音频文件,但想一个接一个播放。我看到了一些东西,但它确实不起作用。例如,我希望声音继续,“ken”将在“lo”之后播放:
-(IBAction)LO:(id)sender{
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"LO", CFSTR ("wav"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
}
-(IBAction)KEN:(id)sender {
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"KEN", CFSTR ("wav"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
}
答案 0 :(得分:2)
你必须低于系统声音。如果它很简单,您可以使用AVAudioPlayer
并在每次获得声音完成的委托回调时触发下一个声音。像
#pragma mark - AVAudioPlayerDelegate
– (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)success {
if (success) {
// last sound finished successfully, play the next sound
[self playNextSound];
} else {
// something went wrong, show an error?
}
}
/*
* Play the next sound
*/
- (void)playNextSound {
// get the file location of the next sound using whatever logic
// is appropriate
NSURL *soundURL = getNextSoundURL();
NSError *error = nil;
// declare an AVAudioPlayer property on your class
self.audioPlayer = [[AVAudioPlayer alloc] initWithURL:soundURL error:&error];
if (nil != error) {
// something went wrong... handle the error
return;
}
self.audioPlayer.delegate = self;
// start the audio playing back
if(![self.audioPlayer play]) {
// something went wrong... handle the error
}
}