
- (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,我还没有找到解决方法.
任何帮助将非常感激.
解决方法 错误560557684适用于AVAudioSessionErrorCodeCannotinterruptOthers.当您的后台应用程序尝试激活不与其他音频会话混合的音频会话时,会发生这种情况.后台应用程序无法启动不与前台应用程序的音频会话混合的音频会话,因为这会中断当前用户正在使用的应用程序的音频.要解决此问题,请确保将会话类别设置为可混合的会话类别,例如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 AVAudioSessionErrorCodeCannotinterruptOthers 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){... AVAudioSessionErrorCodeCannotinterruptOthers = '!int',/* 0x21696E74,560557684 */... 总结 以上是内存溢出为你收集整理的ios – AVAudioRecorder在音频会话中断结束后不在后台录制全部内容,希望文章能够帮你解决ios – AVAudioRecorder在音频会话中断结束后不在后台录制所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)