gpt4 book ai didi

iphone:AVAudioRecorder 录音总是返回 FALSE

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:51:20 25 4
gpt4 key购买 nike

我正在使用 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];

最佳答案

尝试在 [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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com