我有一个应用程序,用户可以在其中按住按钮来拍摄视频。但是,当他们这样做然后放开时,带有视频回放的新层不会立即出现。相反,只有很短的延迟,您可以看到相机在用户松开按钮后仍显示相机看到的内容。延迟结束后,视频立即显示并开始播放。相反,我该如何在准备播放视频之前将其显示为第一帧,以便在播放之前有一小段时间?查看gmails的视频拍摄功能,了解我的意思
我相信解决此问题的方法是立即在第一帧中添加子层,但是我无法找到我该如何精确地做到这一点
以下是我的代码:
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()
}
}
答案 0 :(得分:0)
在stopRecording()函数末尾插入captureSession.stopRunning()
。