Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
chaudharyvikram opened this issue Dec 9, 2019 · 4 comments

Comments

@chaudharyvikram
Copy link

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
Copy link

Any update?

@chaudharyvikram
Copy link
Author

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
Copy link

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

@chaudharyvikram
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants