Iphone 一个接一个播放音频文件?
我想播放音频文件,但想一个接一个地播放。我看到了一些东西,但它并没有真正起作用。例如,我希望声音继续,在“lo”之后将播放“ken”:Iphone 一个接一个播放音频文件?,iphone,ios,xcode,ipad,ios5,Iphone,Ios,Xcode,Ipad,Ios5,我想播放音频文件,但想一个接一个地播放。我看到了一些东西,但它并没有真正起作用。例如,我希望声音继续,在“lo”之后将播放“ken”: 你必须去比系统声音低的地方。如果简单的话,您可以在每次收到代理回调时使用并发出下一个声音,即声音已经完成。差不多 #pragma mark - AVAudioPlayerDelegate – (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)success
你必须去比系统声音低的地方。如果简单的话,您可以在每次收到代理回调时使用并发出下一个声音,即声音已经完成。差不多
#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
}
}
很抱歉,我对这个很陌生。我不明白我是如何将代码与我的代码示例联系起来的。你能给我举个例子吗?。谢谢
#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
}
}