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
- Run the app
- Turn the toggle on
- It asks permission, give permission
- It starts recording video and plays as UNMUTED which is correct.
- Now turn the toggle off
- It starts recording video BUT plays as UNMUTED which is NOT correct.
Scenario #2
- Run the app
- Keep toggle off
- It asks permission, give permission
- It starts recording video and plays as muted which is correct.
- Now turn toggle on
- 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)
}
}