gpt4 book ai didi

swift - replaykit 是否允许录制屏幕然后播放屏幕?

转载 作者:IT王子 更新时间:2023-10-29 05:37:57 26 4
gpt4 key购买 nike

我遇到了一个问题,在我直播我的屏幕后,我尝试录制屏幕,但它不起作用。当我录制屏幕然后尝试直播屏幕时,也会发生同样的事情。顺便说一句,我不想​​一起做。这是在完成一个之后,我尝试使用另一个。如果您需要查看代码或更多信息,请告诉我。我在 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

}

最佳答案

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

关于swift - replaykit 是否允许录制屏幕然后播放屏幕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39684306/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com