Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does replaykit allow to record the screen and then broadcast the screen?

Im having a problem where after I broadcast my screen live, I then try to record the screen but it doesn't work. Same thing happens when I record my screen and then I try to broadcast the screen live. Im not trying to do them together btw. This is after one is done and I try to use the other one. Let me know if you need to see code or more info. Im in Swift 3 and using the new replay kit framework. Thanks!

EDIT: THIS IS THE CODE IM USING

//LIVE STREAM REPLAYKIT=====================================================================
func broadcastActivityViewController(_ broadcastAVC: RPBroadcastActivityViewController, didFinishWith broadcastController: RPBroadcastController?, error: Error?) {
    print("=====hello delegate \(broadcastController?.broadcastURL) (error)")

    self.broadcastController = broadcastController
    self.broadcastController?.delegate = self

    broadcastAVC.dismiss(animated: true) {
        self.broadcastController?.startBroadcast(handler: { error in

            print("start broadcast \(error)")
            print("\(broadcastController?.broadcastExtensionBundleID)")
            print("==url=\(broadcastController?.broadcastURL)")
            print("==serviceInfo=\(broadcastController?.serviceInfo)")

    //This is called when the broadcast is live

    })
  }
}


func broadcastController(_ broadcastController: RPBroadcastController, didFinishWithError error: Error?) {
    print("broadcastController====delegate")

    let alert = UIAlertController(title: "Alert", message: "There was an error broadcasting your screen. Please try again", preferredStyle: UIAlertControllerStyle.alert)

    // show the alert
    self.view!.window?.rootViewController!.present(alert, animated: true, completion: nil)

    alert.addAction(UIAlertAction(title: "Okay", style: UIAlertActionStyle.destructive, handler: { action in

        // add action
   }))
}



 func broadcastController(_ broadcastController: RPBroadcastController, didUpdateServiceInfo serviceInfo: [String : NSCoding & NSObjectProtocol]) {
    print("broadcastController====didUpdateServiceInfo")
  }

  //LIVE STREAM REPLAYKIT=========================================================


 //RECORD SCREEN REPLAYKIT-------------------------------------------------------------------
func startRecoding() {
    let recorder = RPScreenRecorder.shared()
    if recorder.isAvailable {
        recorder.startRecording(handler: { (error) in


   if error == nil { // Recording has started


    } else {
                // Handle error
                print("Dont Allow Recording")

    }
 })

    } else {
        print("Did not record screen")

        //if iphone or ipad doesnt support replaykit

        // create the alert
        let alert = UIAlertController(title: "Alert", message: "Please make sure your device supports ReplayKit!", preferredStyle: UIAlertControllerStyle.alert)


        // show the alert
        self.view!.window?.rootViewController!.present(alert, animated: true, completion: nil)

        alert.addAction(UIAlertAction(title: "Try Again!", style: UIAlertActionStyle.destructive, handler: { action in
            // add action

    }))
  }
}


func stopRecording() {

    let sharedRecorder = RPScreenRecorder.shared()
    sharedRecorder.stopRecording(handler: { (previewViewController: RPPreviewViewController?, error) in

 if previewViewController != nil {
            print("stopped recording")

            previewViewController!.previewControllerDelegate = self

            let alertController = UIAlertController(title: "Recording", message: "Tap view to watch, edit, share, or save your screen recording!", preferredStyle: .alert)

            let viewAction = UIAlertAction(title: "View", style: .default, handler: { (action: UIAlertAction) -> Void in

                self.view?.window?.rootViewController?.present(previewViewController!, animated: true, completion: nil)

 })

            alertController.addAction(viewAction)
            self.previewViewController = previewViewController!
            self.previewViewController.modalPresentationStyle = UIModalPresentationStyle.fullScreen
            self.view?.window?.rootViewController!.present(alertController, animated: true, completion: nil)
 }


 else {
            print("recording stopped working")

            //create the alert================================

            let alert = UIAlertController(title: "Alert", message: "Sorry, there was an error recording your screen. Please Try Again!", preferredStyle: UIAlertControllerStyle.alert)

            // show the alert
            self.view!.window?.rootViewController!.present(alert, animated: true, completion: nil)

            alert.addAction(UIAlertAction(title: "Try Again!", style: UIAlertActionStyle.destructive, handler: { action in
                // add action

          }))
       }
   })
 }


func previewControllerDidFinish(_ previewViewController: RPPreviewViewController) {

print("cancel and save button pressed")

previewViewController.dismiss(animated: true, completion: nil)
//dismiss preview view controller when save or cancel button pressed

}
like image 887
coding22 Avatar asked Sep 25 '16 07:09

coding22


People also ask

What is broadcast in screen recording on iPhone?

If you tap on the “Start Broadcast” button, it merely captures the screen, just like the screen recording button. It then saves the video files to the camera roll.

What is ReplayKit?

The ReplayKit namespace provides classes that allows screen recording of the developer's application. Additionally, it provides a standard RPPreviewViewController view controller that allows the user to preview, trim, and share the recording. Developers must use the SharedRecorder singleton to create replays.


1 Answers

I believe that this is a bug in ReplayKit, I'm not sure if it has been resolved as of 10.1 or not, but it is worth trying the 10.1 beta to see if it solves your issue.

like image 94
jgh Avatar answered Sep 26 '22 04:09

jgh