我正在寻找一种方法来录制从另一个应用程序在后台播放的音频。例如,能够录制 Pandora/Spotify 正在播放的内容。
据我所知,这是不可能的,但 Snapchat 的最新更新支持录制视频时的背景音频。
This post显示如何允许音频在后台继续,但是一旦我设置 [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryRecord error:nil];
背景音频立即停止。
Snapchat 如何让背景音频在录制时继续播放?
最佳答案
初始化AVCaptureSession
时设置其属性:
AVCaptureSession *session = [[AVCaptureSession alloc] init];
...
session.automaticallyConfiguresApplicationAudioSession = NO;
在开始你的视频录制之前,设置你的AVAudioSession
类别:
if ([AVAudioSession sharedInstance].category != AVAudioSessionCategoryPlayAndRecord) {
[[AVAudioSession sharedInstance] setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:nil];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:(AVAudioSessionCategoryOptionDefaultToSpeaker | AVAudioSessionCategoryOptionDuckOthers) error:nil];
[[AVAudioSession sharedInstance] setActive:YES error:nil];
}
关于ios - 从另一个在后台播放的应用程序录制音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28846661/