0

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

[[ AVAudioRecorder alloc] initWithURL:_fileURL settings:settings error:&_error];

一旦停止录音机并成功保存文件,需要立即播放录制的文件。

问题是什么时候可以读取文件并播放它。可以使用哪个委托 API?

4

2 回答 2

1

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];
        }
    }
}
于 2012-01-23T13:33:39.193 回答
0

您是否尝试过使用

- (void) audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder successfully:(BOOL)flag 
{
    // Play the audio
}
于 2012-01-23T13:05:38.183 回答