Recording a video stops. fileOutput(_ output: AVCaptureFileOutput, didFinishRecordingTo outputFileURL: error :: “No such file.” The 2019 Stack Overflow Developer Survey Results Are Inios endless video recordingCoreBluetooth Advertising not startingFirebase swift ios login system error Assertion failed/Exec_BAD_INSTRUNCTION (code=EXC_i386_INVOP, subcode=0x0)Update or reload UITableView after completion of delete action on detail viewI keep getting a use unresolved identifier error swifti cant seem to find the size of the file when im recording audioGLKView.display() method sometimes causes crash. EXC_BAD_ACCESSConvert ViewController Code for RTSP to Swift File to Call into View ControllerAVFoundation video recording stops when camera is switched.Why is an iPhone XS getting worse CPU performance when using the camera live than an iPhone 6S Plus?
Did Scotland spend $250,000 for the slogan "Welcome to Scotland"?
A word that means fill it to the required quantity
Will it cause any balance problems to have PCs level up and gain the benefits of a long rest mid-fight?
Kerning for subscripts of sigma?
Pokemon Turn Based battle (Python)
Falsification in Math vs Science
Correct punctuation for showing a character's confusion
How can I define good in a religion that claims no moral authority?
Accepted by European university, rejected by all American ones I applied to? Possible reasons?
Can there be female White Walkers?
Is it safe to harvest rainwater that fell on solar panels?
Mathematics of imaging the black hole
For what reasons would an animal species NOT cross a *horizontal* land bridge?
Worn-tile Scrabble
Why are there uneven bright areas in this photo of black hole?
Finding the area between two curves with Integrate
The difference between dialogue marks
A female thief is not sold to make restitution -- so what happens instead?
Can a flute soloist sit?
What is this sharp, curved notch on my knife for?
Why was M87 targeted for the Event Horizon Telescope instead of Sagittarius A*?
Button changing its text & action. Good or terrible?
What is the meaning of Triage in Cybersec world?
"as much details as you can remember"
Recording a video stops. fileOutput(_ output: AVCaptureFileOutput, didFinishRecordingTo outputFileURL: error :: “No such file.”
The 2019 Stack Overflow Developer Survey Results Are Inios endless video recordingCoreBluetooth Advertising not startingFirebase swift ios login system error Assertion failed/Exec_BAD_INSTRUNCTION (code=EXC_i386_INVOP, subcode=0x0)Update or reload UITableView after completion of delete action on detail viewI keep getting a use unresolved identifier error swifti cant seem to find the size of the file when im recording audioGLKView.display() method sometimes causes crash. EXC_BAD_ACCESSConvert ViewController Code for RTSP to Swift File to Call into View ControllerAVFoundation video recording stops when camera is switched.Why is an iPhone XS getting worse CPU performance when using the camera live than an iPhone 6S Plus?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm facing problem while recording the video.
The flow is like :-
- I'll launch my camera screen.
- will record a video then will move to create post screen.
- This flow works fine for first time. But when I came back to camera from create post screen, and again try to record, It suddenly stops the recording as soon as i start and throws an error " there is no such file".
Any help would be appreciated.
Thanks.
var captureSession: AVCaptureSession?
var capturePhotoOutput: AVCapturePhotoOutput?
var videoPreviewLayer: AVCaptureVideoPreviewLayer?
var userSelectedFlashMode: AVCaptureDevice.FlashMode = .off
override func viewDidAppear(_ animated: Bool)
super.viewDidAppear(animated)
captureSession = AVCaptureSession()
captureSession?.beginConfiguration()
let microphone = AVCaptureDevice.default(for: AVMediaType.audio)
do
let micInput = try AVCaptureDeviceInput(device: microphone!)
if (captureSession?.canAddInput(micInput))!
captureSession?.addInput(micInput)
catch
print("SRL Error setting device audio input.")
guard let captureDevice = AVCaptureDevice.default(.builtInWideAngleCamera, for: AVMediaType.video, position: .back) else
fatalError("No video device found")
do
let input = try AVCaptureDeviceInput(device: captureDevice)
captureSession?.addInput(input)
capturePhotoOutput = AVCapturePhotoOutput()
capturePhotoOutput?.isHighResolutionCaptureEnabled = true
captureSession?.addOutput(capturePhotoOutput!)
captureSession?.sessionPreset = .high
movieFileOutput.maxRecordedDuration = CMTimeMake(value: Int64(59), timescale: 1)
if (captureSession?.canAddOutput(movieFileOutput))!
captureSession?.addOutput(movieFileOutput)
self.captureSession?.commitConfiguration()
let captureMetadataOutput = AVCaptureMetadataOutput()
captureSession?.addOutput(captureMetadataOutput)
captureMetadataOutput.setMetadataObjectsDelegate(self as? AVCaptureMetadataOutputObjectsDelegate, queue: DispatchQueue.main)
captureMetadataOutput.metadataObjectTypes = [AVMetadataObject.ObjectType.qr]
videoPreviewLayer = AVCaptureVideoPreviewLayer(session: captureSession!)
videoPreviewLayer?.videoGravity = AVLayerVideoGravity.resizeAspectFill
videoPreviewLayer?.frame = previewLayer.layer.bounds
previewLayer.layer.addSublayer(videoPreviewLayer!)
captureSession?.startRunning()
self.btnCapture.isUserInteractionEnabled = true
catch let error
print(error.localizedDescription)
override func viewWillDisappear(_ animated: Bool)
super.viewWillDisappear(animated)
if let captureSession = self.captureSession
if captureSession.isRunning
captureSession.stopRunning()
self.captureSession = nil
self.btnCapture.isUserInteractionEnabled = false
Extension for AVCaptureFileOutputRecordingDelegate
extension MediaCaptureViewCotroller: AVCaptureFileOutputRecordingDelegate
@objc func longPress(_ sender: UILongPressGestureRecognizer)
var device : AVCaptureDevice!
let videoDeviceDiscoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInWideAngleCamera], mediaType: AVMediaType.video, position: .unspecified)
let devices = videoDeviceDiscoverySession.devices
device = devices[0]
if sender.state == .began
print("Started...")
self.hideControls()
let videoPreviewLayerOrientation = videoPreviewLayer?.connection?.videoOrientation
if !movieFileOutput.isRecording
print("Recording...")
if UIDevice.current.isMultitaskingSupported
self.backgroundRecordingID = UIApplication.shared.beginBackgroundTask(expirationHandler: nil)
let movieFileOutputConnection = movieFileOutput.connection(with: .video)
movieFileOutputConnection?.videoOrientation = videoPreviewLayerOrientation!
let availableVideoCodecTypes = movieFileOutput.availableVideoCodecTypes
if #available(iOS 11.0, *)
if availableVideoCodecTypes.contains(.hevc)
movieFileOutput.setOutputSettings([AVVideoCodecKey: AVVideoCodecType.hevc], for: movieFileOutputConnection!)
else
movieFileOutput.setOutputSettings([AVVideoCodecKey: AVVideoCodecH264], for: movieFileOutputConnection!)
if ((device as AnyObject).hasMediaType(AVMediaType.video))
if (device.hasTorch)
self.captureSession?.beginConfiguration()
do
if (device.hasTorch)
catch
print("Device tourch Flash Error ");
self.captureSession?.commitConfiguration()
let outputFileName = NSUUID().uuidString
let outputFilePath = (NSTemporaryDirectory() as NSString).appendingPathComponent(("outputFileName" as NSString).appendingPathExtension("mp4")!)
print("RecordingStart PAth", outputFilePath)
self.cleanup(path: outputFilePath)
movieFileOutput.startRecording(to: URL(fileURLWithPath: outputFilePath), recordingDelegate: self)
else if sender.state == .ended
print("Ended...")
if movieFileOutput.isRecording
print("Stopped")
movieFileOutput.stopRecording()
if ((device as AnyObject).hasMediaType(AVMediaType.video))
if (device.hasTorch)
self.captureSession?.beginConfiguration()
do
if (device.hasTorch)
try device.lockForConfiguration()
device.torchMode = .off
device.unlockForConfiguration()
catch
print("Device tourch Flash Error ");
self.captureSession?.commitConfiguration()
self.showControls()
else
func fileOutput(_ output: AVCaptureFileOutput, didFinishRecordingTo outputFileURL: URL, from connections: [AVCaptureConnection], error: Error?)
print(outputFileURL.absoluteString)
do
let data = try Data(contentsOf: outputFileURL)
print("Recorded File size", data.count)
//FIXME:- Navigate to create post screen
catch
print("error in decoding file", error.localizedDescription)
self.showControls()
func cleanup(path: String)
if FileManager.default.fileExists(atPath: path)
do
try FileManager.default.removeItem(atPath: path)
catch
print("Could not remove file at url: (path)")
if let currentBackgroundRecordingID = backgroundRecordingID
backgroundRecordingID = UIBackgroundTaskIdentifier.invalid
if currentBackgroundRecordingID != UIBackgroundTaskIdentifier.invalid
UIApplication.shared.endBackgroundTask(currentBackgroundRecordingID)
swift cocoa-touch avfoundation ios10 ios12
add a comment |
I'm facing problem while recording the video.
The flow is like :-
- I'll launch my camera screen.
- will record a video then will move to create post screen.
- This flow works fine for first time. But when I came back to camera from create post screen, and again try to record, It suddenly stops the recording as soon as i start and throws an error " there is no such file".
Any help would be appreciated.
Thanks.
var captureSession: AVCaptureSession?
var capturePhotoOutput: AVCapturePhotoOutput?
var videoPreviewLayer: AVCaptureVideoPreviewLayer?
var userSelectedFlashMode: AVCaptureDevice.FlashMode = .off
override func viewDidAppear(_ animated: Bool)
super.viewDidAppear(animated)
captureSession = AVCaptureSession()
captureSession?.beginConfiguration()
let microphone = AVCaptureDevice.default(for: AVMediaType.audio)
do
let micInput = try AVCaptureDeviceInput(device: microphone!)
if (captureSession?.canAddInput(micInput))!
captureSession?.addInput(micInput)
catch
print("SRL Error setting device audio input.")
guard let captureDevice = AVCaptureDevice.default(.builtInWideAngleCamera, for: AVMediaType.video, position: .back) else
fatalError("No video device found")
do
let input = try AVCaptureDeviceInput(device: captureDevice)
captureSession?.addInput(input)
capturePhotoOutput = AVCapturePhotoOutput()
capturePhotoOutput?.isHighResolutionCaptureEnabled = true
captureSession?.addOutput(capturePhotoOutput!)
captureSession?.sessionPreset = .high
movieFileOutput.maxRecordedDuration = CMTimeMake(value: Int64(59), timescale: 1)
if (captureSession?.canAddOutput(movieFileOutput))!
captureSession?.addOutput(movieFileOutput)
self.captureSession?.commitConfiguration()
let captureMetadataOutput = AVCaptureMetadataOutput()
captureSession?.addOutput(captureMetadataOutput)
captureMetadataOutput.setMetadataObjectsDelegate(self as? AVCaptureMetadataOutputObjectsDelegate, queue: DispatchQueue.main)
captureMetadataOutput.metadataObjectTypes = [AVMetadataObject.ObjectType.qr]
videoPreviewLayer = AVCaptureVideoPreviewLayer(session: captureSession!)
videoPreviewLayer?.videoGravity = AVLayerVideoGravity.resizeAspectFill
videoPreviewLayer?.frame = previewLayer.layer.bounds
previewLayer.layer.addSublayer(videoPreviewLayer!)
captureSession?.startRunning()
self.btnCapture.isUserInteractionEnabled = true
catch let error
print(error.localizedDescription)
override func viewWillDisappear(_ animated: Bool)
super.viewWillDisappear(animated)
if let captureSession = self.captureSession
if captureSession.isRunning
captureSession.stopRunning()
self.captureSession = nil
self.btnCapture.isUserInteractionEnabled = false
Extension for AVCaptureFileOutputRecordingDelegate
extension MediaCaptureViewCotroller: AVCaptureFileOutputRecordingDelegate
@objc func longPress(_ sender: UILongPressGestureRecognizer)
var device : AVCaptureDevice!
let videoDeviceDiscoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInWideAngleCamera], mediaType: AVMediaType.video, position: .unspecified)
let devices = videoDeviceDiscoverySession.devices
device = devices[0]
if sender.state == .began
print("Started...")
self.hideControls()
let videoPreviewLayerOrientation = videoPreviewLayer?.connection?.videoOrientation
if !movieFileOutput.isRecording
print("Recording...")
if UIDevice.current.isMultitaskingSupported
self.backgroundRecordingID = UIApplication.shared.beginBackgroundTask(expirationHandler: nil)
let movieFileOutputConnection = movieFileOutput.connection(with: .video)
movieFileOutputConnection?.videoOrientation = videoPreviewLayerOrientation!
let availableVideoCodecTypes = movieFileOutput.availableVideoCodecTypes
if #available(iOS 11.0, *)
if availableVideoCodecTypes.contains(.hevc)
movieFileOutput.setOutputSettings([AVVideoCodecKey: AVVideoCodecType.hevc], for: movieFileOutputConnection!)
else
movieFileOutput.setOutputSettings([AVVideoCodecKey: AVVideoCodecH264], for: movieFileOutputConnection!)
if ((device as AnyObject).hasMediaType(AVMediaType.video))
if (device.hasTorch)
self.captureSession?.beginConfiguration()
do
if (device.hasTorch)
catch
print("Device tourch Flash Error ");
self.captureSession?.commitConfiguration()
let outputFileName = NSUUID().uuidString
let outputFilePath = (NSTemporaryDirectory() as NSString).appendingPathComponent(("outputFileName" as NSString).appendingPathExtension("mp4")!)
print("RecordingStart PAth", outputFilePath)
self.cleanup(path: outputFilePath)
movieFileOutput.startRecording(to: URL(fileURLWithPath: outputFilePath), recordingDelegate: self)
else if sender.state == .ended
print("Ended...")
if movieFileOutput.isRecording
print("Stopped")
movieFileOutput.stopRecording()
if ((device as AnyObject).hasMediaType(AVMediaType.video))
if (device.hasTorch)
self.captureSession?.beginConfiguration()
do
if (device.hasTorch)
try device.lockForConfiguration()
device.torchMode = .off
device.unlockForConfiguration()
catch
print("Device tourch Flash Error ");
self.captureSession?.commitConfiguration()
self.showControls()
else
func fileOutput(_ output: AVCaptureFileOutput, didFinishRecordingTo outputFileURL: URL, from connections: [AVCaptureConnection], error: Error?)
print(outputFileURL.absoluteString)
do
let data = try Data(contentsOf: outputFileURL)
print("Recorded File size", data.count)
//FIXME:- Navigate to create post screen
catch
print("error in decoding file", error.localizedDescription)
self.showControls()
func cleanup(path: String)
if FileManager.default.fileExists(atPath: path)
do
try FileManager.default.removeItem(atPath: path)
catch
print("Could not remove file at url: (path)")
if let currentBackgroundRecordingID = backgroundRecordingID
backgroundRecordingID = UIBackgroundTaskIdentifier.invalid
if currentBackgroundRecordingID != UIBackgroundTaskIdentifier.invalid
UIApplication.shared.endBackgroundTask(currentBackgroundRecordingID)
swift cocoa-touch avfoundation ios10 ios12
add a comment |
I'm facing problem while recording the video.
The flow is like :-
- I'll launch my camera screen.
- will record a video then will move to create post screen.
- This flow works fine for first time. But when I came back to camera from create post screen, and again try to record, It suddenly stops the recording as soon as i start and throws an error " there is no such file".
Any help would be appreciated.
Thanks.
var captureSession: AVCaptureSession?
var capturePhotoOutput: AVCapturePhotoOutput?
var videoPreviewLayer: AVCaptureVideoPreviewLayer?
var userSelectedFlashMode: AVCaptureDevice.FlashMode = .off
override func viewDidAppear(_ animated: Bool)
super.viewDidAppear(animated)
captureSession = AVCaptureSession()
captureSession?.beginConfiguration()
let microphone = AVCaptureDevice.default(for: AVMediaType.audio)
do
let micInput = try AVCaptureDeviceInput(device: microphone!)
if (captureSession?.canAddInput(micInput))!
captureSession?.addInput(micInput)
catch
print("SRL Error setting device audio input.")
guard let captureDevice = AVCaptureDevice.default(.builtInWideAngleCamera, for: AVMediaType.video, position: .back) else
fatalError("No video device found")
do
let input = try AVCaptureDeviceInput(device: captureDevice)
captureSession?.addInput(input)
capturePhotoOutput = AVCapturePhotoOutput()
capturePhotoOutput?.isHighResolutionCaptureEnabled = true
captureSession?.addOutput(capturePhotoOutput!)
captureSession?.sessionPreset = .high
movieFileOutput.maxRecordedDuration = CMTimeMake(value: Int64(59), timescale: 1)
if (captureSession?.canAddOutput(movieFileOutput))!
captureSession?.addOutput(movieFileOutput)
self.captureSession?.commitConfiguration()
let captureMetadataOutput = AVCaptureMetadataOutput()
captureSession?.addOutput(captureMetadataOutput)
captureMetadataOutput.setMetadataObjectsDelegate(self as? AVCaptureMetadataOutputObjectsDelegate, queue: DispatchQueue.main)
captureMetadataOutput.metadataObjectTypes = [AVMetadataObject.ObjectType.qr]
videoPreviewLayer = AVCaptureVideoPreviewLayer(session: captureSession!)
videoPreviewLayer?.videoGravity = AVLayerVideoGravity.resizeAspectFill
videoPreviewLayer?.frame = previewLayer.layer.bounds
previewLayer.layer.addSublayer(videoPreviewLayer!)
captureSession?.startRunning()
self.btnCapture.isUserInteractionEnabled = true
catch let error
print(error.localizedDescription)
override func viewWillDisappear(_ animated: Bool)
super.viewWillDisappear(animated)
if let captureSession = self.captureSession
if captureSession.isRunning
captureSession.stopRunning()
self.captureSession = nil
self.btnCapture.isUserInteractionEnabled = false
Extension for AVCaptureFileOutputRecordingDelegate
extension MediaCaptureViewCotroller: AVCaptureFileOutputRecordingDelegate
@objc func longPress(_ sender: UILongPressGestureRecognizer)
var device : AVCaptureDevice!
let videoDeviceDiscoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInWideAngleCamera], mediaType: AVMediaType.video, position: .unspecified)
let devices = videoDeviceDiscoverySession.devices
device = devices[0]
if sender.state == .began
print("Started...")
self.hideControls()
let videoPreviewLayerOrientation = videoPreviewLayer?.connection?.videoOrientation
if !movieFileOutput.isRecording
print("Recording...")
if UIDevice.current.isMultitaskingSupported
self.backgroundRecordingID = UIApplication.shared.beginBackgroundTask(expirationHandler: nil)
let movieFileOutputConnection = movieFileOutput.connection(with: .video)
movieFileOutputConnection?.videoOrientation = videoPreviewLayerOrientation!
let availableVideoCodecTypes = movieFileOutput.availableVideoCodecTypes
if #available(iOS 11.0, *)
if availableVideoCodecTypes.contains(.hevc)
movieFileOutput.setOutputSettings([AVVideoCodecKey: AVVideoCodecType.hevc], for: movieFileOutputConnection!)
else
movieFileOutput.setOutputSettings([AVVideoCodecKey: AVVideoCodecH264], for: movieFileOutputConnection!)
if ((device as AnyObject).hasMediaType(AVMediaType.video))
if (device.hasTorch)
self.captureSession?.beginConfiguration()
do
if (device.hasTorch)
catch
print("Device tourch Flash Error ");
self.captureSession?.commitConfiguration()
let outputFileName = NSUUID().uuidString
let outputFilePath = (NSTemporaryDirectory() as NSString).appendingPathComponent(("outputFileName" as NSString).appendingPathExtension("mp4")!)
print("RecordingStart PAth", outputFilePath)
self.cleanup(path: outputFilePath)
movieFileOutput.startRecording(to: URL(fileURLWithPath: outputFilePath), recordingDelegate: self)
else if sender.state == .ended
print("Ended...")
if movieFileOutput.isRecording
print("Stopped")
movieFileOutput.stopRecording()
if ((device as AnyObject).hasMediaType(AVMediaType.video))
if (device.hasTorch)
self.captureSession?.beginConfiguration()
do
if (device.hasTorch)
try device.lockForConfiguration()
device.torchMode = .off
device.unlockForConfiguration()
catch
print("Device tourch Flash Error ");
self.captureSession?.commitConfiguration()
self.showControls()
else
func fileOutput(_ output: AVCaptureFileOutput, didFinishRecordingTo outputFileURL: URL, from connections: [AVCaptureConnection], error: Error?)
print(outputFileURL.absoluteString)
do
let data = try Data(contentsOf: outputFileURL)
print("Recorded File size", data.count)
//FIXME:- Navigate to create post screen
catch
print("error in decoding file", error.localizedDescription)
self.showControls()
func cleanup(path: String)
if FileManager.default.fileExists(atPath: path)
do
try FileManager.default.removeItem(atPath: path)
catch
print("Could not remove file at url: (path)")
if let currentBackgroundRecordingID = backgroundRecordingID
backgroundRecordingID = UIBackgroundTaskIdentifier.invalid
if currentBackgroundRecordingID != UIBackgroundTaskIdentifier.invalid
UIApplication.shared.endBackgroundTask(currentBackgroundRecordingID)
swift cocoa-touch avfoundation ios10 ios12
I'm facing problem while recording the video.
The flow is like :-
- I'll launch my camera screen.
- will record a video then will move to create post screen.
- This flow works fine for first time. But when I came back to camera from create post screen, and again try to record, It suddenly stops the recording as soon as i start and throws an error " there is no such file".
Any help would be appreciated.
Thanks.
var captureSession: AVCaptureSession?
var capturePhotoOutput: AVCapturePhotoOutput?
var videoPreviewLayer: AVCaptureVideoPreviewLayer?
var userSelectedFlashMode: AVCaptureDevice.FlashMode = .off
override func viewDidAppear(_ animated: Bool)
super.viewDidAppear(animated)
captureSession = AVCaptureSession()
captureSession?.beginConfiguration()
let microphone = AVCaptureDevice.default(for: AVMediaType.audio)
do
let micInput = try AVCaptureDeviceInput(device: microphone!)
if (captureSession?.canAddInput(micInput))!
captureSession?.addInput(micInput)
catch
print("SRL Error setting device audio input.")
guard let captureDevice = AVCaptureDevice.default(.builtInWideAngleCamera, for: AVMediaType.video, position: .back) else
fatalError("No video device found")
do
let input = try AVCaptureDeviceInput(device: captureDevice)
captureSession?.addInput(input)
capturePhotoOutput = AVCapturePhotoOutput()
capturePhotoOutput?.isHighResolutionCaptureEnabled = true
captureSession?.addOutput(capturePhotoOutput!)
captureSession?.sessionPreset = .high
movieFileOutput.maxRecordedDuration = CMTimeMake(value: Int64(59), timescale: 1)
if (captureSession?.canAddOutput(movieFileOutput))!
captureSession?.addOutput(movieFileOutput)
self.captureSession?.commitConfiguration()
let captureMetadataOutput = AVCaptureMetadataOutput()
captureSession?.addOutput(captureMetadataOutput)
captureMetadataOutput.setMetadataObjectsDelegate(self as? AVCaptureMetadataOutputObjectsDelegate, queue: DispatchQueue.main)
captureMetadataOutput.metadataObjectTypes = [AVMetadataObject.ObjectType.qr]
videoPreviewLayer = AVCaptureVideoPreviewLayer(session: captureSession!)
videoPreviewLayer?.videoGravity = AVLayerVideoGravity.resizeAspectFill
videoPreviewLayer?.frame = previewLayer.layer.bounds
previewLayer.layer.addSublayer(videoPreviewLayer!)
captureSession?.startRunning()
self.btnCapture.isUserInteractionEnabled = true
catch let error
print(error.localizedDescription)
override func viewWillDisappear(_ animated: Bool)
super.viewWillDisappear(animated)
if let captureSession = self.captureSession
if captureSession.isRunning
captureSession.stopRunning()
self.captureSession = nil
self.btnCapture.isUserInteractionEnabled = false
Extension for AVCaptureFileOutputRecordingDelegate
extension MediaCaptureViewCotroller: AVCaptureFileOutputRecordingDelegate
@objc func longPress(_ sender: UILongPressGestureRecognizer)
var device : AVCaptureDevice!
let videoDeviceDiscoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInWideAngleCamera], mediaType: AVMediaType.video, position: .unspecified)
let devices = videoDeviceDiscoverySession.devices
device = devices[0]
if sender.state == .began
print("Started...")
self.hideControls()
let videoPreviewLayerOrientation = videoPreviewLayer?.connection?.videoOrientation
if !movieFileOutput.isRecording
print("Recording...")
if UIDevice.current.isMultitaskingSupported
self.backgroundRecordingID = UIApplication.shared.beginBackgroundTask(expirationHandler: nil)
let movieFileOutputConnection = movieFileOutput.connection(with: .video)
movieFileOutputConnection?.videoOrientation = videoPreviewLayerOrientation!
let availableVideoCodecTypes = movieFileOutput.availableVideoCodecTypes
if #available(iOS 11.0, *)
if availableVideoCodecTypes.contains(.hevc)
movieFileOutput.setOutputSettings([AVVideoCodecKey: AVVideoCodecType.hevc], for: movieFileOutputConnection!)
else
movieFileOutput.setOutputSettings([AVVideoCodecKey: AVVideoCodecH264], for: movieFileOutputConnection!)
if ((device as AnyObject).hasMediaType(AVMediaType.video))
if (device.hasTorch)
self.captureSession?.beginConfiguration()
do
if (device.hasTorch)
catch
print("Device tourch Flash Error ");
self.captureSession?.commitConfiguration()
let outputFileName = NSUUID().uuidString
let outputFilePath = (NSTemporaryDirectory() as NSString).appendingPathComponent(("outputFileName" as NSString).appendingPathExtension("mp4")!)
print("RecordingStart PAth", outputFilePath)
self.cleanup(path: outputFilePath)
movieFileOutput.startRecording(to: URL(fileURLWithPath: outputFilePath), recordingDelegate: self)
else if sender.state == .ended
print("Ended...")
if movieFileOutput.isRecording
print("Stopped")
movieFileOutput.stopRecording()
if ((device as AnyObject).hasMediaType(AVMediaType.video))
if (device.hasTorch)
self.captureSession?.beginConfiguration()
do
if (device.hasTorch)
try device.lockForConfiguration()
device.torchMode = .off
device.unlockForConfiguration()
catch
print("Device tourch Flash Error ");
self.captureSession?.commitConfiguration()
self.showControls()
else
func fileOutput(_ output: AVCaptureFileOutput, didFinishRecordingTo outputFileURL: URL, from connections: [AVCaptureConnection], error: Error?)
print(outputFileURL.absoluteString)
do
let data = try Data(contentsOf: outputFileURL)
print("Recorded File size", data.count)
//FIXME:- Navigate to create post screen
catch
print("error in decoding file", error.localizedDescription)
self.showControls()
func cleanup(path: String)
if FileManager.default.fileExists(atPath: path)
do
try FileManager.default.removeItem(atPath: path)
catch
print("Could not remove file at url: (path)")
if let currentBackgroundRecordingID = backgroundRecordingID
backgroundRecordingID = UIBackgroundTaskIdentifier.invalid
if currentBackgroundRecordingID != UIBackgroundTaskIdentifier.invalid
UIApplication.shared.endBackgroundTask(currentBackgroundRecordingID)
swift cocoa-touch avfoundation ios10 ios12
swift cocoa-touch avfoundation ios10 ios12
asked Mar 8 at 11:15
Harshal YanpallewarHarshal Yanpallewar
992410
992410
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55062089%2frecording-a-video-stops-fileoutput-output-avcapturefileoutput-didfinishreco%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55062089%2frecording-a-video-stops-fileoutput-output-avcapturefileoutput-didfinishreco%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown