Does replaykit allow to record the screen and then broadcast the screen?
Asked Answered
M

1

12

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

}
Mesdames answered 25/9, 2016 at 7:5 Comment(7)
Please clarify, you're broadcasting the screen, the player finishes, then you want to save the video that was broadcast to disk?Cameraman
The problem is after I'm done broadcasting the screen I press stop and then try to record the screen and it doesn't work. I don't want to save the video that was broadcasted. I just want to be able to record the screen and when that's over then broadcast the screen. I don't know if you saw the new replay kit framework but u can record the screen and also broadcast the screen live. I just don't know if it's allowed to use both in an app.Mesdames
They both work fine but if I do it back to back. Like if I record the screen first it works and then I want to broadcast the screen live it won't work. Same thing happens if I do it in reverse where I broadcast the screen live first it works but when I then I try to record the screen it won't work. I'm not sure why that happens.Mesdames
You'll need to include some code in your question.Cameraman
I'm not home right now but I will once I getMesdames
@Cameraman I added the code, could you please take a look?Mesdames
Sounds like a possible bug, or at least worth filing one with Apple to check.Trinidad
S
1

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.

Swor answered 15/10, 2016 at 1:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.