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

标签 ios avaudiorecorder avaudiosession

通过

将一些内容记录到指定文件中
[[ AVAudioRecorder alloc] initWithURL:_fileURL settings:settings error:&_error];

停止录音机并成功保存文件后需要立即播放录音文件。

问题是如何何时可以读取文件并播放它。可以使用哪个委托(delegate) API?

最佳答案

设置 AVAudioRecorder 实例的委托(delegate)

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];
        }
    }
}

关于ios - 如何通过成功将音频保存到文件来知道 AVAudioRecorder 何时停止?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8130584/

相关文章:

iphone - 当发生中断时如何让我的音频应用程序在后台保持事件状态?

ios - 显示 MPMediaPickerController 模态后状态栏再次出现

ios - 在日期 Swift 2 的比较中订购相同不返回结果

iphone - 如何使用 AVAudioRecorder 恢复录音?

ios - AVAudio Recorder 不在后台录音

ios - AVAudioEngine.start() 中的崩溃,即使它被包裹在 do/catch 中

iphone - 如何避免SIG_PIPE在IOS中崩溃

ios - Objective-C - 预期类型 + 函数

iphone - 路由 iPhone 音频声音

iOS 在没有 Audio Session 的情况下播放视频