首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AVAudioRecorder切断录音

AVAudioRecorder切断录音
EN

Stack Overflow用户
提问于 2013-05-10 17:59:22
回答 1查看 556关注 0票数 0

我有一个使用AVAudioRecorder和AVAudioPlayer的应用程序。它记录和播放很好,但有时录音会在一分钟左右被切断。这并不是所有时候都会发生的,当它发生时,它仍然表现为它在录制(audioRecorderEncodeErrorDidOccur不会被调用,而audioRecorderDidFinishRecording会在用户停止录制时被调用)。但是声音文件本身在一分钟内就会被截断。

下面是我正在使用的编码(soundFileURL是appsdocdir/某某事物随机。m4a,文件和文件名被正确创建):

代码语言:javascript
复制
NSDictionary *recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue:[NSNumber numberWithInt:kAudioFormatAppleLossless] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
[recordSetting setValue:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[recordSetting setValue:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
[recordSetting setValue:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];

NSError *error = nil;
self->audioRecorder = nil;
audioRecorder = [[AVAudioRecorder alloc]
                 initWithURL:soundFileURL
                 settings:recordSetting
                 error:&error];

if (error)
{
    NSLog(@"error: %@", [error localizedDescription]);

} else {
    audioRecorder.delegate = self;
    [audioRecorder prepareToRecord];
    audioRecorder.meteringEnabled = YES;
}

我认为这是一个编码问题,因为如果我查看设备日志,就会看到以下内容:

5月10:17:23 t-iPhone mediaserverd39 : 10:17:23.451 <0x282f000> AudioConverterNew返回-50 5月10日10:17:23 t-iPhone mediaserverd39 : 10:17:23.453 <0x282f000> IO_ChangeIOFormat: error -50 5月10日10:17:23 t-iPhone mediaserverd39 : 10:17:23.463 <0x282f000> Queue_ChangeIOFormat: failed (-50)

编辑:有人问soundFileURL是什么。我在上面简要地提到了它,但这是实际的代码。文件和文件名在记录后看起来都是正确的:

代码语言:javascript
复制
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MMMMdyyyyA"];
NSString *recordDate = [formatter stringFromDate:[NSDate date]];

filename = [[NSString alloc] initWithFormat:@"%d-%@.m4a", idNumber, recordDate];
NSArray *dirPaths;
NSString *docsDir;

dirPaths = NSSearchPathForDirectoriesInDomains(
                                               NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
NSString *soundFilePath = [docsDir
                           stringByAppendingPathComponent:filename];
soundFileURL = [NSURL fileURLWithPath:soundFilePath];
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-05-10 22:48:11

我想通了。问题是电话要睡觉了。从睡觉的时候到从锁屏出来的时候,它都会剪掉任何声音。我修正了将UIBackgroundModes ->音频添加到info.plist文件中:

http://developer.apple.com/library/ios/#documentation/general/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16488176

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档