【问题标题】:Does replaykit allow to record the screen and then broadcast the screen?replaykit 是否允许录屏然后播放屏幕?
【发布时间】:2016-09-25 07:05:06
【问题描述】:

我有一个问题,在我直播我的屏幕后,我尝试录制屏幕,但它不起作用。当我录制我的屏幕然后我尝试直播屏幕时也会发生同样的事情。顺便说一句,我不想​​把它们一起做。这是在完成一个之后,我尝试使用另一个。如果您需要查看代码或更多信息,请告诉我。我在 Swift 3 中并使用新的重播工具包框架。谢谢!

编辑:这是我正在使用的代码

//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

}

【问题讨论】:

  • 请澄清,您正在播放屏幕,播放器结束,然后您要将播放的视频保存到磁盘?
  • 问题是在我播放完屏幕后我按停止然后尝试录制屏幕但它不起作用。我不想保存已播放的视频。我只是希望能够录制屏幕,然后播放屏幕。我不知道您是否看到了新的回放套件框架,但您可以录制屏幕并直播屏幕。我只是不知道是否允许在应用中同时使用两者。
  • 它们都工作得很好,但如果我背靠背做的话。就像我先录制屏幕它可以工作,然后我想现场直播屏幕它就行不通了。如果我反过来做同样的事情,我首先直播屏幕,但当我尝试录制屏幕时,它就不起作用了。我不知道为什么会这样。
  • 您需要在问题中包含一些代码。
  • 我现在不在家,但我一到就去

标签: swift xcode replaykit


【解决方案1】:

我认为这是 ReplayKit 中的一个错误,我不确定它是否已在 10.1 中得到解决,但值得尝试 10.1 测试版,看看它是否能解决您的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-24
    • 1970-01-01
    • 1970-01-01
    • 2017-01-30
    • 1970-01-01
    • 2021-06-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多