0
這是我試圖播放的視頻文件類型的示例: file:/// private/var/mobile/Containers/Data/Application/7725BCCA-B709-48FB-8FE3-DBC9F4B679C0/tmp/9AD6A48E -6A25-4114-88D3-474A0E1C762F.mp4如何回放錄製的視頻?
我認爲這是錄音,但當我嘗試播放錄製的視頻時,它只是一個空白屏幕。
func startRecording() {
print("start")
if movieOutput.isRecording == false {
let connection = movieOutput.connection(withMediaType: AVMediaTypeVideo)
if (connection?.isVideoOrientationSupported)! {
connection?.videoOrientation = currentVideoOrientation()
}
if (connection?.isVideoStabilizationSupported)! {
connection?.preferredVideoStabilizationMode = AVCaptureVideoStabilizationMode.auto
}
print(AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo))
let device = activeInput.device
if (device?.isSmoothAutoFocusSupported)! {
do {
try device?.lockForConfiguration()
device?.isSmoothAutoFocusEnabled = false
device?.unlockForConfiguration()
} catch {
print("Error setting configuration: \(error)")
}
}
outputURL = tempURL()
movieOutput.startRecording(toOutputFileURL: outputURL, recordingDelegate: self)
} else {
print("stop")
stopRecording()
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showPreview" {
let previewVC = segue.destination as! ProfilePhotoPreviewViewController
previewVC.image = self.image
} else if segue.identifier == "showVideoPreview" {
let vc = segue.destination as! ProfilePhotoPreviewViewController
vc.videoURL = videoRecorded
}
}
}
extension TakePhotoViewController: AVCaptureFileOutputRecordingDelegate {
func capture(_ captureOutput: AVCaptureFileOutput!, didStartRecordingToOutputFileAt fileURL: URL!, fromConnections connections: [Any]!) {
}
func capture(_ captureOutput: AVCaptureFileOutput!, didFinishRecordingToOutputFileAt outputFileURL: URL!, fromConnections connections: [Any]!, error: Error!) {
if (error != nil) {
print("Error recording movie: \(error!.localizedDescription)")
} else {
videoRecorded = outputURL! as URL
print(videoRecorded)
print("recorded")
performSegue(withIdentifier: "showVideoPreview", sender: nil)
}
}
}