قالب وردپرس درنا توس
Home / IOS Development / ios – Swift: View (AVCaptureVideoPreviewLayer) freezes when rejecting VC?

ios – Swift: View (AVCaptureVideoPreviewLayer) freezes when rejecting VC?



I have a basic camera app similar to snapchats when a user takes a photo they go to preview and can see the image. When they are finished, they can press a button that will put VC a DGO back to the camera. This works fine, but when a user takes a video, it previewes it, so when they press the Cancel button, rejects the VC, the view where they can take photos can be frozen.

To fix this problem, I had originally made a sigue instead of a termination. But I found this to make the interrupt function very slow. So my question is how can I solve this freezing problem?

Below is how I surpass now out of VC preview:

  @IBAction func cancelButton (_ send: UIButton) {
reject (animated: false, completion: null)
// deletes video data
self.playerQueue? .removeAllItems ()
}

Bellow find previewVC where Vids and images are displayed

  class PreviewViewController: UIViewController {

@IBOutlet weak was mediaView: UIImageView!

was picture: wool painting!

// To hide the status bar:
// was statusBarHidden: Bool?

override func viewDidLoad () {
super.viewDidLoad ()

print (self.image)
mediaView.image = self.image

// bellow is too wide

whose video url! = null {
print ("videoURL", videoURL)

playerItem1
= AVPlayerItem (URL: videoURL as URL) print (playerItem1, "playerItem1") playerQueue = AVQueuePlayer (playerItem: playerItem1) print (player queue, player queue) playerLayer = AVPlayerLayer (player: playerQueue) print (playerLayer, "playerLayer") playerLooper = AVPlayerLooper (player: playerQueue, templateItem: playerItem1) print (player looper, player looper) playerLayer.frame = view.bounds playerLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill print (mediaview, "yruewioq") mediaView.layer.insertSublayer (playerLayer, at: 0) view.layoutIfNeeded () self.playerQueue? Protect your Nintendo DS () } } //SAVE: @IBAction func saveButton (_ sender: UIButton) { if videoURL == nil { UIImageWriteToSavedPhotosAlbum (image, null, null, null) reject (animated: false, completion: null) } } //TO FINISH: @IBAction func cancelButton (_ sender: UIButton) { reject (animated: false, completion: null) } // receives URL video value from VideoViewController was videoURL: URL! private var playerQueue: AVQueuePlayer! private was playerItem1: AVPlayerItem! private was playerLooper: AVPlayerLooper! private were playerLayer: AVPlayerLayer! }

Bellow is my viewDidLoad () in mainVC

  override func viewDidLoad () {
super.viewDidLoad ()
print ("67423814700000000")
// INTEGRATION NIEK 24 (ASK IF NOT INTEGRATED)
whose setupInputOutput () {
print ("in this gfgf")
setupCaptureSession ()
setupDevice ()
// setupInputOutput ()
// setupPreviewLayer ()
startRunningCaptureSession ()
}
setupPreviewLayer ()


// INTEGRATED during Nov 24 START = - = - = - = - = -
// for the button --- ||||||||||||||
cameraButton.isUserInteractionEnabled = true

let tapGesture = UITapGestureRecognizer (goal: self, action: #selector (normalTap (_ :)))
tapGesture.numberOfTapsRequired = 1
cameraButton.addGestureRecognizer (tapGesture)

la longGesture = UILongPressGestureRecognizer (goal: self, action: #selector (longTap (_ :)))
longGesture.minimumPressDuration = 0.15
//longGesture.allowableMovement = 100

// This functionality below may be imp?
// longGesture.delaysTouchesBegan
cameraButton.addGestureRecognizer (longGesture)

camPreview.addSubview (cameraButton)
// INTEGRATED during Nov 24 END = - = - = - = - = -

}

Update : It's freezing at the frame that was taken when the user let go of the catch button.


Source link