我的iPhone应用程序使用"AVAudioRecorder"进行录音.它还使用"UIImagePickerController"来录制电影,使用"MPMoviePlayerController"来播放电影.
一切正常,直到我连续做三件事:
当我在步骤3中调用AVAudioRecorder的"记录"方法时,它返回NO表示失败,但没有提示为什么(来到Apple!)AVAudioRecorder的audioRecorderEncodeErrorDidOccur委托方法永远不会被调用,我在设置录像机时没有收到任何其他错误.
我的第一个猜测是,电影录制/播放正在以一种阻止录音机工作的方式修改"AVAudioSession"的共享实例.但是,我手动将AVAudioSession的类别属性设置为"AVAudioSessionCategoryRecord",并且在尝试录制之前使音频会话处于活动状态.
这是我创建录音机的方法:
- (void)createAudioRecorder
{
NSError *error = nil;
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryRecord error:&error];
if (error)
...
[audioSession setActive:YES error:&error];
if (error)
...
NSMutableDictionary *settings = [[NSMutableDictionary alloc] init];
// General Audio Format Settings
[settings setValue:[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];
[settings setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[settings setValue:[NSNumber numberWithInt:1] forKey:AVNumberOfChannelsKey];
// Encoder Settings
[settings setValue:[NSNumber numberWithInt:AVAudioQualityMin] forKey:AVEncoderAudioQualityKey];
[settings setValue:[NSNumber numberWithInt:96] forKey:AVEncoderBitRateKey];
[settings setValue:[NSNumber numberWithInt:16] forKey:AVEncoderBitDepthHintKey];
// Write the audio to a temporary file
NSURL *tempURL …Run Code Online (Sandbox Code Playgroud) iphone mpmovieplayercontroller uiimagepickercontroller avaudiorecorder