RPScreenRecorder startCaptureWithHandler:不在样本处理程序中返回麦克风声音

问题描述 投票:1回答:1

我试图在我的iPad上用iOS 11.4使用RPScreenRecorder startCaptureWithHandler:completionHandler:api来直接获取音频和视频。它适用于应用程序屏幕,应用程序音频和相机,但是当我使用microphoneEnabled = YES打开麦克风时,我从未在回调中获得麦克风的任何音频样本。

我在info.plist中添加了麦克风隐私使用密钥,但这没有帮助。

我不知道接下来我可以做些什么来尝试解决这个问题。

谢谢。

objective-c microphone rpscreenrecorder
1个回答
1
投票

此代码获取包含实际麦克风音频的音频缓冲区(即使没有麦克风使用字符串或音频会话配置):

RPScreenRecorder *recorder = [RPScreenRecorder sharedRecorder];

recorder.microphoneEnabled = YES;

[recorder startCaptureWithHandler:^(CMSampleBufferRef sampleBuffer, RPSampleBufferType bufferType, NSError* error) {
    NSLog(@"Capture %@, %li, %@", sampleBuffer, (long)bufferType, error);
    if (RPSampleBufferTypeAudioMic == bufferType) {
        // Do something with mic audio
    }
} completionHandler:^(NSError* error) {
    NSLog(@"startCapture: %@", error);
}];

有一个权限对话框,询问您是允许屏幕和麦克风,仅允许屏幕还是不允许。您是否可以点击屏幕?注:我不知道如何重置此对话框。

另一种可能性是你在开始捕捉后设置microphoneEnabled?那可能行不通。不,这对我也有用。

以前猜测

您可能需要激活录制AVAudioSession

try! AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryRecord)  // or AVAudioSessionCategoryPlayAndRecord!
try! AVAudioSession.sharedInstance().setActive(true)
© www.soinside.com 2019 - 2024. All rights reserved.