【发布时间】:2015-04-24 15:10:18
【问题描述】:
我正在IOS上使用linphone开发VOIP应用程序。
我使用 [[LinphoneManager instance] startLibLinphone] 函数进行 linphone sdk 初始化。
然后我使用下面的代码进行录音。
但是我得到了录制失败的错误。
如何使用 linphone sdk 录制音频?
谢谢。
NSError *error;
// Recording settings
NSDictionary *settings = @{AVEncoderAudioQualityKey: @(AVAudioQualityMedium),
AVFormatIDKey: @(kAudioFormatMPEG4AAC),
AVEncoderBitRateKey: @(128000),
AVNumberOfChannelsKey: @(1),
AVSampleRateKey: @(44100),
AVLinearPCMBitDepthKey:@(8)};
// File URL
NSURL *url = [NSURL fileURLWithPath:pathToSave];//FILEPATH];
// Create recorder
recorder = [[AVAudioRecorder alloc] initWithURL:url settings:settings error:&error];
if (!recorder)
{
NSLog(@"Error establishing recorder: %@", error.localizedFailureReason);
return NO;
}
recorder.delegate = delegate;
recorder.meteringEnabled = YES;
if (![recorder prepareToRecord])
{
NSLog(@"Error: Prepare to record failed");
return NO;
}
if (![recorder record])
{
NSLog(@"Error: Record failed");
return NO;
}
【问题讨论】:
-
您得到的确切错误是什么?
-
我在下面的代码中遇到了错误。 if (![recorder record]) { NSLog(@"Error: Record failed");返回否; }
-
我解决了这个问题。我添加了下面的代码。 AVAudioSession *audioSession = [AVAudioSession sharedInstance]; NSError *err = nil; [audioSession setCategory :AVAudioSessionCategoryPlayAndRecord 错误:&err]; if(err){ NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);返回; } [audioSession setActive:YES 错误:&err];
标签: ios audio record voip linphone