RPScreenRecorder startCaptureWithHandler: not returning microphone sound in sample handler

放肆的年华 提交于 2020-01-16 06:57:42

问题


I am trying to use RPScreenRecorder startCaptureWithHandler:completionHandler: api on my iPad with iOS 11.4 to grab audio and video directly. It works well with the app screen, app audio and the camera, but when I turn on the microphone using microphoneEnabled = YES, I never get any audio sample for the mic in the callback.

I added the microphone privacy usage key in the info.plist but that did not help.

I am not sure what I can do next to try to resolve this issue.

Thanks.


回答1:


This code gets me audio buffers containing actual microphone audio (even without a microphone usage string or audio session configuration):

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);
}];

There's a permission dialog that asks whether you Allow Screen & Microphone, Allow Screen Only, or don't allow. Is it possible you tapped screen-only? N.B. I don't know how to reset this dialog.

The other possibility is that you're setting microphoneEnabled after you start capturing? That might not work. Nah, that works for me too.

Previous guess

You might need to activate a recording AVAudioSession:

try! AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryRecord)  // or AVAudioSessionCategoryPlayAndRecord!
try! AVAudioSession.sharedInstance().setActive(true)


来源:https://stackoverflow.com/questions/50935432/rpscreenrecorder-startcapturewithhandler-not-returning-microphone-sound-in-samp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!