I've modified a SwiftUI tutorial with a gesture button to record videos like so:
var longPress: some Gesture {
DragGesture(minimumDistance: 0)
.updating($isDetectingLongPress) { currentState, gestureState,
transaction in
gestureState = true
transaction.animation = Animation.easeIn(duration: 2.0)
model.captureButtonHold()
}
.onEnded { finished in
print("Finished long press")
model.stopRecording()
self.completedLongPress = true
}
}
However, the captureVideoAndMetadata func (below) doesn't capture or print anything except Capture video called..., and of course after the gesture is complete it prints (Finished long press). Any suggestions? Thanks in advance
This is the captureVideoAndMetada func:
private func captureVideoAndMetadata() {
logger.log("Capture video called...")
dispatchPrecondition(condition: .onQueue(.main))
/// This property retrieves and stores the video preview layer's video orientation on the main
/// queue before starting the session queue. This ensures that UI elements can be accessed on
/// the main thread.
let videoPreviewLayerOrientation = session.connections[0].videoOrientation
guard let movieFileOutput = self.movieFileOutput else {
return
}
sessionQueue.async {
if !movieFileOutput.isRecording {
if UIDevice.current.isMultitaskingSupported {
self.backgroundRecordingID = UIApplication.shared.beginBackgroundTask(expirationHandler: nil)
}
// Update the orientation on the movie file output video connection before recording.
let movieFileOutputConnection = movieFileOutput.connection(with: .video)
movieFileOutputConnection?.videoOrientation = videoPreviewLayerOrientation
let availableVideoCodecTypes = movieFileOutput.availableVideoCodecTypes
if availableVideoCodecTypes.contains(.hevc) {
movieFileOutput.setOutputSettings([AVVideoCodecKey: AVVideoCodecType.hevc], for: movieFileOutputConnection!)
}
// Start recording video to a temporary file.
let outputFileName = NSUUID().uuidString
let outputFilePath = (NSTemporaryDirectory() as NSString).appendingPathComponent((outputFileName as NSString).appendingPathExtension("mov")!)
movieFileOutput.startRecording(to: URL(fileURLWithPath: outputFilePath), recordingDelegate: self)
print("Creating capture path: (movieFileOutput)")
} else {
movieFileOutput.stopRecording()
}
}
}