bugfix:录音的时候,webview不能播放视频

来源:互联网 发布:淘宝舞蹈服 编辑:程序博客网 时间:2024/05/22 00:25

现象:

使用webview显示html,html中有播放视频,同时设备正在录音。

模拟器中没有问题,录音可以生成,视频也可以播放。

但是真机中,录音可以生成,但是视频无法播放。

真机中报错:

[0x3b05518c] Received corrupt data. Property list is  NULLERROR:     [0x3b05518c] AVAudioSessionUtilities.h:88: GetProperty_DefaultToZero: AudioSessionGetProperty ('tfac') failed with error: 'tahw'


原因:

根据报错信息,找到一篇文章:

http://stackoverflow.com/questions/22222501/audiosessiongetproperty-tfac-failed-with-error-tahw

// Configure audio session[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];

其中提到了AVAudioSession这个类。

查看下项目中对应的代码,由于录音的时候,没有考虑播放的问题,所以项目中直接使用的AVAudioSessionCategoryRecord

AVAudioSession *session = [AVAudioSession sharedInstance];NSError *sessionError;[session setCategory:AVAudioSessionCategoryRecord error:&sessionError];


这就是导致录音时,不能播放视频的原因了。

解决办法:

查看AVAudioSessionCategory其他的值:

#pragma mark -- Values for the category property --/*  Use this category for background sounds such as rain, car engine noise, etc.   Mixes with other music. */AVF_EXPORT NSString *const AVAudioSessionCategoryAmbient;/*  Use this category for background sounds.  Other music will stop playing. */AVF_EXPORT NSString *const AVAudioSessionCategorySoloAmbient;/* Use this category for music tracks.*/AVF_EXPORT NSString *const AVAudioSessionCategoryPlayback;/*  Use this category when recording audio. */AVF_EXPORT NSString *const AVAudioSessionCategoryRecord;/*  Use this category when recording and playing back audio. */AVF_EXPORT NSString *const AVAudioSessionCategoryPlayAndRecord;/*  Use this category when using a hardware codec or signal processor while not playing or recording audio. */AVF_EXPORT NSString *const AVAudioSessionCategoryAudioProcessing;/*  Use this category to customize the usage of available audio accessories and built-in audio hardware. For example, this category provides an application with the ability to use an available USB output  and headphone output simultaneously for separate, distinct streams of audio data. Use of  this category by an application requires a more detailed knowledge of, and interaction with,  the capabilities of the available audio routes.  May be used for input, output, or both. Note that not all output types and output combinations are eligible for multi-route.  Input is limited to the last-in input port. Eligible inputs consist of the following:AVAudioSessionPortUSBAudio, AVAudioSessionPortHeadsetMic, and AVAudioSessionPortBuiltInMic.   Eligible outputs consist of the following: AVAudioSessionPortUSBAudio, AVAudioSessionPortLineOut, AVAudioSessionPortHeadphones, AVAudioSessionPortHDMI, and AVAudioSessionPortBuiltInSpeaker.   Note that AVAudioSessionPortBuiltInSpeaker is only allowed to be used when there are no other eligible  outputs connected.  */AVF_EXPORT NSString *const AVAudioSessionCategoryMultiRoute NS_AVAILABLE_IOS(6_0);

根据需要同时录音、播放视频的需求,改为:

AVAudioSession *session = [AVAudioSession sharedInstance];NSError *sessionError;[session setCategory:AVAudioSessionCategoryPlayAndRecord         withOptions:AVAudioSessionCategoryOptionMixWithOthers               error:&sessionError];

参考资料:

http://stackoverflow.com/questions/22222501/audiosessiongetproperty-tfac-failed-with-error-tahw

iOS AudioSession详解


0 0
原创粉丝点击