pierreveron / SwiftUICam

A Snapchat Style Camera View to use with a SwiftUI interface
MIT License
91 stars 20 forks source link

Video crashes on start #5

Open leobuckman opened 2 years ago

leobuckman commented 2 years ago

Crashes with error message:

Movie file finishing error: Optional(Error Domain=AVFoundationErrorDomain Code=-11859 "Movie recording cannot be started" UserInfo={NSUnderlyingError=0x281c02df0 {Error Domain=NSOSStatusErrorDomain Code=-16419 "(null)"}, NSLocalizedFailureReason=A movie recording is already in progress., NSLocalizedRecoverySuggestion=Stop the movie recording in progress and try again., AVErrorRecordingFailureDomainKey=1, NSLocalizedDescription=Movie recording cannot be started})

Crashes in this part of CameraViewController:

if error != nil { print("Movie file finishing error: \(String(describing: error))") success = (((error! as NSError).userInfo[AVErrorRecordingSuccessfullyFinishedKey] as AnyObject).boolValue)! }

Any idea as to why this is happening?

alexmanning14 commented 1 year ago

Same issue for me as well.

I think the problem is that toggleMovieRecording() in CameraView is called repetitively while events.didAskToRecordVideo is true, thus causing the video to toggle on and off near instantly. I think we need a solution to ensure it is only called and run once per call to toggleVideoRecording().

Screenshot 2023-02-19 at 9 00 59 PM

*Update - I added a simple boolean to CameraViewController (public var inProgress: Bool = false) and changed CameraView to this and it works: image

**Update - The same issue occurs for the camera flipping. Add a boolean in CameraViewController (public var isCameraFlipping: Bool = false) and add this to CameraView: image Also, set the boolean back to false at the last line of rotateCamera()