piemonte / PBJVision

📸 iOS Media Capture – features touch-to-record video, slow motion, and photography
MIT License
1.94k stars 324 forks source link

PBJMediaWriter crash on endVideoCapture #323

Closed dimovskidamjan closed 3 years ago

dimovskidamjan commented 8 years ago

Hi,

When I try to end recording a video, the app crashes at [_assetWriterVideoInput markAsFinished]; or [_assetWriterAudioInput markAsFinished];. This never happened to me before iOS10, but since it was release I've had to update my Info.plist file to include the newly required "Privacy" strings Privacy - Camera Usage Description, Privacy - Media Library Usage Description and Privacy - Microphone Usage Description. The crash happens only at first try, when the user is prompted by the to give access to the Camera and Microphone. If the user accepts both and continues recording the video, then tries to end video capture, the app crashes. If the user has already given these permissions before, the app will not crash and will work as expected.

So I'm guessing it's something to do with the permissions. Should I not wait for the popup to appear automatically? Should I somehow ask for the permissions before the video capture starts?

Any help would be greatly appreciated.

piemonte commented 8 years ago

hey @dimovskidamjan i recently started developing a swift version of this library and encountered the same situation. there is API to check the permission status, which you can call to avoid when the authorization is triggered. i haven't solved it in the other library yet just because i've been so busy but it's on my checklist, can bring it over here too.

here's some links that'll help:

📎 https://github.com/NextLevel/NextLevel/blob/master/Sources/NextLevel.swift#L921-L922 📎 https://github.com/NextLevel/NextLevel/blob/master/Sources/NextLevel.swift#L672-L686

checklist: ✅ https://github.com/NextLevel/NextLevel/issues/5

dimovskidamjan commented 8 years ago

@piemonte I have managed to fix it by asking for permissions before starting PBJVision, like so:

[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
            if (granted) {
                [AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio completionHandler:^(BOOL granted) {
                    if (granted) {
                        //Your PBJVision code goes here...
                    }
                }];
            }
}];

In my case, this was for recording a video with audio, that's why I needed both permissions granted. This has stopped the crashing of the app.