很抱歉,如果这是重复的,但我找不到类似的问题。我有一个我用AVFoundation制作的自定义摄像机/录像机,我想知道如何在录制视频的同时保持音频从其他应用程序运行,因为它现在停止音频(甚至不会暂停它),然后记录视频
如果我正确思考,可以通过添加类似的内容来解决这个问题:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil];
答案 0 :(得分:1)
示例代码:
AVAudioSession *session = [AVAudioSession sharedInstance];
session.delegate = self;
NSError *error = nil;
[session setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
OSStatus propertySetError = 0;
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
propertySetError = AudioSessionSetProperty (
kAudioSessionProperty_OverrideAudioRoute,
sizeof (audioRouteOverride),
&audioRouteOverride
);
[session setActive:YES error:&error];
答案 1 :(得分:1)
This fixed it.
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord
withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker | AVAudioSessionCategoryOptionMixWithOthers
error:nil];