大佬教程收集整理的这篇文章主要介绍了ios – AVAudioRecorder在音频会话中断结束后不在后台录制,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
- (void)p_handleAudioSessionInterruptionNotification:(Nsnotification *)notification { NSUInteger interruptionType = [[[notification userInfo] objectForKey:AVAudioSessionInterruptionTypeKey] unsignedIntegerValue]; if (interruptionType == AVAudioSessionInterruptionTypeBegan) { if (self.isRecording && !self.interruptedWhileRecording) { [self.recorder stop]; self.interruptedWhileRecording = YES; return; } } if (interruptionType == AVAudioSessionInterruptionTypeEnded) { if (self.interruptedWhileRecording) { NSError *error = nil; [[AVAudioSession sharedInstance] setActive:YES error:&error]; NSDictionary *setTings = @{ AVEncoderAudioQualityKey: @(AVAudioQualitymaX),AVSampleRateKey: @8000,AVFormatIDKey: @(kAudioFormatLinearPCM),AVnumberOfChAnnelsKey: @1,AVLinearPCMBitDepthKey: @16,AVLinearPCMIsBigendianKey: @NO,AVLinearPCMIsFloatKey: @NO }; _recorder = [[AVAudioRecorder alloc] initWithURL:fileURL setTings:setTings error:nil]; [self.recorder record]; self.interruptedWhileRecording = NO; return; } } }
请注意,fileURL指向NSDocumentDirectory子目录中的新caf文件.配置背景模式音频.我也试过voip和沉默,都没有成功.
AVAudioSessionInterruptionTypeEnded块中的NSError是OSStatus错误560557684,我还没有找到解决方法.
任何帮助将非常感激.
要解决此问题,请确保将会话类别设置为可混合的会话类别,例如AVAudioSessionCategoryPlayBACk.另外一定要设置类别选项AVAudioSessionCategoryOptionMixWithOthers(必需)和AVAudioSessionCategoryOptionDuckOthers(可选).例如:
// BACkground audio *must* mix with other sessions (or setActive will fail) NSError *sessionError = nil; [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayBACk withOptions:AVAudioSessionCategoryOptionMixWithOthers | AVAudioSessionCategoryOptionDuckOthers error:&sessionError]; if (sessionError) { NSLog(@"ERROR: setCategory %@",[sessionError localizedDescription]); }
错误代码560557684实际上是32位整数中的4个ascii字符’!int’.错误代码列在AVAudioSession.h文件中(另请参见AVAudioSession):
@enum AVAudioSession error codes @abstract these are the error codes returned from the AVAudioSession API. ... @constant AVAudioSessionErrorCodeCan@L_801_24@terruptOthers The app's audio session is non-mixable and trying to go active while in the BACkground. This is allowed only when the app is the NowPlaying app. typedef NS_ENUM(NSInteger,AVAudioSessionErrorCodE) { ... AVAudioSessionErrorCodeCan@L_801_24@terruptOthers = '!int',/* 0x21696E74,560557684 */ ...
以上是大佬教程为你收集整理的ios – AVAudioRecorder在音频会话中断结束后不在后台录制全部内容,希望文章能够帮你解决ios – AVAudioRecorder在音频会话中断结束后不在后台录制所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。