Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 一个接一个播放音频文件?_Iphone_Ios_Xcode_Ipad_Ios5 - Fatal编程技术网

Iphone 一个接一个播放音频文件?

Iphone 一个接一个播放音频文件?,iphone,ios,xcode,ipad,ios5,Iphone,Ios,Xcode,Ipad,Ios5,我想播放音频文件,但想一个接一个地播放。我看到了一些东西,但它并没有真正起作用。例如,我希望声音继续,在“lo”之后将播放“ken”: 你必须去比系统声音低的地方。如果简单的话,您可以在每次收到代理回调时使用并发出下一个声音,即声音已经完成。差不多 #pragma mark - AVAudioPlayerDelegate – (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)success

我想播放音频文件,但想一个接一个地播放。我看到了一些东西,但它并没有真正起作用。例如,我希望声音继续,在“lo”之后将播放“ken”:


你必须去比系统声音低的地方。如果简单的话,您可以在每次收到代理回调时使用并发出下一个声音,即声音已经完成。差不多

#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
    }
}