Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.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
Ios 如何通过将音频成功保存到文件来知道AVAudioRecorder何时停止?_Ios_Avaudiorecorder_Avaudiosession - Fatal编程技术网

Ios 如何通过将音频成功保存到文件来知道AVAudioRecorder何时停止?

Ios 如何通过将音频成功保存到文件来知道AVAudioRecorder何时停止?,ios,avaudiorecorder,avaudiosession,Ios,Avaudiorecorder,Avaudiosession,通过将某些内容记录到指定的文件中 [[ AVAudioRecorder alloc] initWithURL:_fileURL settings:settings error:&_error]; 一旦停止录音机并成功保存文件,需要立即播放录制的文件 问题是如何确定何时可以读取文件并播放它。可以使用哪个代理api?您是否尝试过使用 - (void) audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder successful

通过将某些内容记录到指定的文件中

[[ AVAudioRecorder alloc] initWithURL:_fileURL settings:settings error:&_error];
一旦停止录音机并成功保存文件,需要立即播放录制的文件

问题是如何确定何时可以读取文件并播放它。可以使用哪个代理api?

您是否尝试过使用

- (void) audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder successfully:(BOOL)flag 
{
    // Play the audio
}

设置
AVAudioRecorder
实例的委托

AVAudioRecorder* test = [[AVAudioRecorder alloc] initWithURL:_fileURL settings:settings error:&_error];
然后实施

- (void) audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder successfully:(BOOL)flag 
{
    // play the recorded audio here
    if (flag)
    {
        NSError* error;
        AVAudioPlayer* player = [[[AVAudioPlayer alloc] initWithContentsOfURL:[recorder url] error:&error] autorelease];
        if (!error)
        {
            [player play];
        }
    }
}