RPScreenRecorder microphone enabled property not working in 13.1.2 and 13.1.3

887 views Asked by At

I am unable to change the screen recorder audio property programmatically. Setting it the first time works correctly, resetting it in the same session gives problem.

Scenario #1

  1. Run the app
  2. Turn the toggle on
  3. It asks permission, give permission
  4. It starts recording video and plays as UNMUTED which is correct.
  5. Now turn the toggle off
  6. It starts recording video BUT plays as UNMUTED which is NOT correct.

Scenario #2

  1. Run the app
  2. Keep toggle off
  3. It asks permission, give permission
  4. It starts recording video and plays as muted which is correct.
  5. Now turn toggle on
  6. It starts recording video BUT plays as MUTED which is NOT correct.

Then I saw there was an update at apple for ios 13.1.3 , I downloaded that too and tried our app, but it act exactly same as above. I was hoping this would fix the issue but it did not make any difference.

ios 12 updates also showed varied results running the same code. This is really very frustrating. Any help will be appreciated.

\-------------------------------------------------------------

import UIKit import ReplayKit

class RecordingViewController: UIViewController, RPPreviewViewControllerDelegate {

var flagIsMicrophoneEnabled = false
let btnSwitch = UISwitch()
let recorder = RPScreenRecorder.shared()
override func viewDidLoad() {
    super.viewDidLoad()
    self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Start", style: .plain, target: self, action: #selector(startRecording))
    btnSwitch.center = self.view.center
    btnSwitch.addTarget(self, action: #selector(changeMicrophoneStatus), for: .valueChanged)
    self.view.addSubview(btnSwitch)
}

@objc func changeMicrophoneStatus(){
    flagIsMicrophoneEnabled = !flagIsMicrophoneEnabled
    print("Is microphone enabled: \(flagIsMicrophoneEnabled)")
}

@objc func startRecording() {
    recorder.isMicrophoneEnabled = flagIsMicrophoneEnabled
    recorder.startRecording{ [unowned self] (error) in
        if let unwrappedError = error {
            print("error#1: ",unwrappedError.localizedDescription)
        } else {
            self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Stop", style: .plain, target: self, action: #selector(self.stopRecording))
        }
    }
}

@objc func stopRecording() {
    print("Is microphone enabled: \(recorder.isMicrophoneEnabled)")
    if recorder.isRecording{
        recorder.stopRecording { [unowned self] (preview, error) in
            self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Start", style: .plain, target: self, action: #selector(self.startRecording))
            if let unwrappedError = error {
                print("error#2: ",unwrappedError.localizedDescription)
            }
            if let unwrappedPreview = preview {
                if UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.pad {
                    unwrappedPreview.modalPresentationStyle = UIModalPresentationStyle.popover
                    unwrappedPreview.popoverPresentationController?.sourceRect = CGRect.zero
                    unwrappedPreview.popoverPresentationController?.sourceView = self.view
                }
                unwrappedPreview.previewControllerDelegate = self
                self.present(unwrappedPreview, animated: true)
            }
        }
    }
}

func previewControllerDidFinish(_ previewController: RPPreviewViewController) {
    dismiss(animated: true)
}

}

0

There are 0 answers