我正在使用 AVAudioRecorder 来录制声音,但是我遇到了问题。
调用[recorder record]方法后,recorder.recording的值一直返回FALSE,让我无法停止录音。
我在 iOS 5 上使用 XCode 4.2,我的 iPad 也是 iOS 5 上的 ipad 2。
这是我的代码:
self.currentFileName = [GlobalRecording newRecordingFileName];
NSURL *url = [NSURL fileURLWithPath:[[GlobalRecording recordingDirectory] stringByAppendingPathComponent:currentFileName]];
NSError *err = nil;
AVAudioRecorder *aRecorder = [[AVAudioRecorder alloc] initWithURL:url settings:recordingSettings error:&err];
if( err ){
NSLog(@"could not create a recorder: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
return;
}
self.startRecordingTime = [NSDate date];
recordingLength = 0.0f;
// setup recorder and start recording
[aRecorder setDelegate:self];
aRecorder.meteringEnabled = YES;
[aRecorder record];
self.recorder = aRecorder;
BOOL test = recorder.recording;
[aRecorder release];
Best Answer-推荐答案 strong>
尝试在 [audioRecord prepareToRecord] 之后使用 AVAudioSession
NSError *err = nil;
audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err];
// route to speaker
UInt32 ASRoute = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty(kAudioSessionProperty_OverrideAudioRoute, sizeof(ASRoute), &ASRoute);
if (err)
{
NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
}
[audioSession setActive:YES error:&err];
关于iphone:AVAudioRecorder 录音总是返回 FALSE,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/7914712/
|