Mobcrush / ReplayKitDemo

Demo project to aid developers who are integrating ReplayKit Live
Other
62 stars 13 forks source link

Attempted to start an invalid broadcast session in live broadcasting using replaykit ios #4

Open chaudharyvikram opened 4 years ago

chaudharyvikram commented 4 years ago

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 converted code from Objective - C to swift from your demo project. It's working fine on my iPhone 5s with iOS 12.4.3, But it's not work in my iPad mini 4 with iPadOS 13.2.3. I can't able to find any document of ReplayKit. Please help me to find ReplayKit documents or any example if available.

Thank you.

AnkitaPundir commented 3 years ago

Any update?

chaudharyvikram commented 3 years ago

No any update. But I think issue in iOS version above 13. I used Direct API of Facebook and Youtube to broadcast screen instead of ReplayKit

AnkitaPundir commented 3 years ago

@chaudharyvikram But to capture the broadcast Screen you have to use replaykit. Right?

chaudharyvikram commented 3 years ago

@AnkitaPundir Yes. I'm getting screen frames from replaykit and passing frames to API's.