I'm currently working on live screen broadcasting app which allows the user's to share their screen on Youtube, Facebook, Mobcrush like apps. Everything is working fine but sometimes broadcast automatically getting stopped and throwing below error, and every time I open the app and after presenting RPBroadcastActivityViewController
and after selecting the app, live preview view of the selected app is dismissed automatically and also RPBroadcastActivityViewController
getting dismissed. Also, I can't able to enable the microphone. If I enable microphone it's throwing an error.
Error when broadcast automatically getting stopped -
Attempted to start an invalid broadcast session
Error when I try to enable microphone -
Microphone recording must be enabled first prior to startRecording
My code :-
extension MainViewController: RPBroadcastActivityViewControllerDelegate {
func broadcastActivityViewController(_ broadcastActivityViewController: RPBroadcastActivityViewController, didFinishWith broadcastController: RPBroadcastController?, error: Error?) {
broadCastVC = broadcastController
broadCastVC?.delegate = self
broadcastActivityViewController.dismiss(animated: true) {
guard error == nil else {
return
}
broadCastVC?.startBroadcast(handler: { (error) in
RPScreenRecorder.shared().delegate = self
RPScreenRecorder.shared().isMicrophoneEnabled = true
guard error != nil else {
return
}
print(stringVal: "Live :- Error:- \(error?.localizedDescription ?? "")")
})
}
}
}
extension MainViewController: RPBroadcastControllerDelegate {
func broadcastController(_ broadcastController: RPBroadcastController, didFinishWithError error: Error?) {
guard error != nil else {
return
}
print(stringVal: "Live :- Error while starting broadcast :- \(error?.localizedDescription ?? "")")
if broadCastVC?.isBroadcasting == true {
broadCastVC?.finishBroadcast(handler: { (error) in
})
}
}
}
extension MainViewController: RPScreenRecorderDelegate { }
extension MainViewController {
@IBAction func switchAudio(_ sender: Any) {
let sharedRecorder = RPScreenRecorder.shared()
sharedRecorder.isMicrophoneEnabled = self.audioSwitch.isOn
}
@IBAction func btnStartBroadCastAction(_ sender: UIButton) {
if broadCastVC?.isBroadcasting == true {
broadCastVC?.finishBroadcast(handler: { (error) in
})
} else {
RPBroadcastActivityViewController.load(handler: { (broadCastACTVC, error) in
if let broadcastAVC = broadCastACTVC {
broadcastAVC.delegate = self
if UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.phone {
self.present(broadcastAVC, animated: true, completion: nil)
} else {
broadcastAVC.popoverPresentationController?.sourceView = self.btnBroadCast
broadcastAVC.modalPresentationStyle = UIModalPresentationStyle.formSheet
broadcastAVC.preferredContentSize = CGSize(width: self.view.frame.width, height: self.view.frame.height)
self.present(broadcastAVC, animated: true, completion: nil)
}
}
})
}
}
}
I can't able to find any document of ReplayKit. Please help me to find ReplayKit documents or any example if available.
Thank you.