如何冻结视图直到某个值为真?
How to freeze the view until a certain value is true?
我有一个应用程序,用户可以在其中按住一个按钮来拍摄视频。然而,当他们这样做然后放手时,新的图层和视频播放不会立即出现。相反,有一个非常短的延迟,您可以看到相机仍然显示用户松开按钮后相机看到的内容。当延迟结束时,视频立即出现并开始播放。我怎样才能让视频的第一帧在准备播放之前出现,以便它在开始播放之前只停留片刻?查看 snapchats 视频拍摄功能了解我的意思
我相信解决这个问题的方法是通过某种方式立即在第一帧添加子层,但是我无法找到我们究竟如何做到这一点
下面是我的代码:
func fileOutput(_ output: AVCaptureFileOutput, didFinishRecordingTo outputFileURL: URL, from connections: [AVCaptureConnection], error: Error?) {
if (error != nil) {
print("Error recording movie11: \(error!.localizedDescription)")
} else {
newViewVideoPlayback()
switchIcon.isHidden = true
switchWhiteUI.isHidden = true
switchCamButton.isHidden = true
camWhiteLine.isHidden = true
let videoRecorded = outputURL! as URL
playerQueue = AVQueuePlayer(playerItem: AVPlayerItem(url: videoRecorded))
self.playerQueue?.play()
playerLayer = AVPlayerLayer(player: playerQueue)
playerLayer.frame = (camPreview?.bounds)!
playerLayer?.layoutIfNeeded()
playerLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill
camPreview?.layer.insertSublayer(playerLayer, above: previewLayer)
playerItem1 = AVPlayerItem(url: videoRecorded)
playerLooper = AVPlayerLooper(player: playerQueue, templateItem: playerItem1)
if !captureSession.isRunning {
DispatchQueue.global(qos: .background).async {
self.startRunningCaptureSession()
}
}
}
}
//Bellow is teh long tap method
@objc func longTap(_ sender: UIGestureRecognizer) {
print("Long tap")
self.numForVid = numForVid + 1 //shud change this number stuff
print("\(numForVid)")
cameraButton.isHidden = true
if sender.state == .ended {
print("UIGestureRecognizerStateEnded")
//stopSession()
stopRecording()
}
else if sender.state == .began {
print("UIGestureRecognizerStateBegan.")
//Do Whatever You want on Began of Gesture
startCapture()
}
}
在 stopRecording() 函数的末尾插入 captureSession.stopRunning()
。
我有一个应用程序,用户可以在其中按住一个按钮来拍摄视频。然而,当他们这样做然后放手时,新的图层和视频播放不会立即出现。相反,有一个非常短的延迟,您可以看到相机仍然显示用户松开按钮后相机看到的内容。当延迟结束时,视频立即出现并开始播放。我怎样才能让视频的第一帧在准备播放之前出现,以便它在开始播放之前只停留片刻?查看 snapchats 视频拍摄功能了解我的意思
我相信解决这个问题的方法是通过某种方式立即在第一帧添加子层,但是我无法找到我们究竟如何做到这一点
下面是我的代码:
func fileOutput(_ output: AVCaptureFileOutput, didFinishRecordingTo outputFileURL: URL, from connections: [AVCaptureConnection], error: Error?) {
if (error != nil) {
print("Error recording movie11: \(error!.localizedDescription)")
} else {
newViewVideoPlayback()
switchIcon.isHidden = true
switchWhiteUI.isHidden = true
switchCamButton.isHidden = true
camWhiteLine.isHidden = true
let videoRecorded = outputURL! as URL
playerQueue = AVQueuePlayer(playerItem: AVPlayerItem(url: videoRecorded))
self.playerQueue?.play()
playerLayer = AVPlayerLayer(player: playerQueue)
playerLayer.frame = (camPreview?.bounds)!
playerLayer?.layoutIfNeeded()
playerLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill
camPreview?.layer.insertSublayer(playerLayer, above: previewLayer)
playerItem1 = AVPlayerItem(url: videoRecorded)
playerLooper = AVPlayerLooper(player: playerQueue, templateItem: playerItem1)
if !captureSession.isRunning {
DispatchQueue.global(qos: .background).async {
self.startRunningCaptureSession()
}
}
}
}
//Bellow is teh long tap method
@objc func longTap(_ sender: UIGestureRecognizer) {
print("Long tap")
self.numForVid = numForVid + 1 //shud change this number stuff
print("\(numForVid)")
cameraButton.isHidden = true
if sender.state == .ended {
print("UIGestureRecognizerStateEnded")
//stopSession()
stopRecording()
}
else if sender.state == .began {
print("UIGestureRecognizerStateBegan.")
//Do Whatever You want on Began of Gesture
startCapture()
}
}
在 stopRecording() 函数的末尾插入 captureSession.stopRunning()
。