[英]AVAssetWriter / AVAudioPlayer Conflict?
几周前,我发布了有关我与AVAssetWriter遇到的问题的线程: AVAssetWriter Woes
进一步的研究似乎导致在使用AVAudioPlayer或实际上任何音频系统播放音频时使用AVAssetWriter引起冲突。 我也尝试过OpenAL。
这是背景:
使用AVAssetWriter从图像或一组图像向视频中写入帧可以正常工作,直到调用[AVAudioPlayer播放]。
这仅在设备上发生,而不在SIM卡上发生。
尝试从CVPixelBufferPoolCreatePixelBuffer创建像素缓冲区时发生错误。
音频开始播放后,突然出现的AVAssetWriterInputPixelBufferAdaptor.pixelBufferPool变为零。
您可以在此处下载代表性项目: http : //www.mediafire.com/?5k7kqyvtbfdgdgv
注释掉AVAudioPlayer的播放,它将在设备上运行。
任何线索表示赞赏。
以上答案已经完成。 没用 改为这样做
// Setup to be able to record global sounds (preexisting app sounds)
NSError *sessionError = nil;
if ([[AVAudioSession sharedInstance] respondsToSelector:@selector(setCategory:withOptions:error:)])
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDuckOthers error:&sessionError];
else
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:&sessionError];
// Set the audio session to be active
[[AVAudioSession sharedInstance] setActive:YES error:&sessionError];
//then call your asset writer
movieWriter = [[AVAssetWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(480.0, 640.0)];
我已经找到解决此问题的方法。
如果要使AVAudioPlayer和AVAssetWriter一起正常运行,则必须具有“可混合”的音频会话类别。
您可以使用可混合使用的类别,例如AVAudioSessionCategoryAmbient。
但是,我需要使用AVAudioSessionCategoryPlayAndRecord。
您可以通过实现以下方式将任何类别设置为可混合使用:
OSStatus propertySetError = 0;
UInt32 allowMixing = true;
propertySetError = AudioSessionSetProperty (
kAudioSessionProperty_OverrideCategoryMixWithOthers, // 1
sizeof (allowMixing), // 2
&allowMixing // 3
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.