2016-09-25 121 views
10

進出口我的屏幕後,我有一個問題,然後我試圖記錄屏幕,但它不起作用。同樣的事情發生在我錄製我的屏幕時,然後我試圖直播現場直播。我沒有試圖做他們一起btw。這是一個完成後,我嘗試使用另一個。如果您需要查看代碼或更多信息,請告知我們。我在Swift 3中使用新的重播套件框架。謝謝!replaykit是否允許記錄屏幕然後播放屏幕?

編輯:這是代碼即時通訊使用

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

} 
+0

請說明,您正在播放屏幕,播放器完成,然後您想要保存播放到磁盤的視頻? – Lance

+0

問題是我完成播放屏幕後,我按停止,然後嘗試記錄屏幕,它不起作用。我不想保存播放的視頻。我只是想能夠記錄屏幕,什麼時候結束,然後播放屏幕。我不知道你是否看到了新的重放套件框架,但是你可以記錄屏幕並且直播現場直播。我只是不知道它是否可以在應用程序中使用。 – coding22

+0

他們都很好,但如果我做它背靠背。就像我先錄製屏幕一樣,然後我想直播屏幕,它將無法工作。同樣的事情發生,如果我做反向,我首先播放它的屏幕直播它的作品,但是當我然後我嘗試記錄屏幕它將無法正常工作。我不知道爲什麼會發生。 – coding22

回答

1

我認爲,這是在ReplayKit一個錯誤,我不知道這是否已經解決爲10.1或不是,但它是值得一試10.1測試版,看它是否能解決你的問題。