Can i continue record video when user put application on background mode?

Hi,


I have an application that uses AVCaptureSession to record the video (from front camera) and write it to file.
When i put an application on background mode i start recieve exception:


AVFoundationErrorDomain Code = -11847 "Opetation Interrupted".


When getting back on foreground, still recieving this exception.


The questions is - can i continue record video when user put application on background mode? If yes, how should i implement it?

If no, is there way to at least pause the recording and continue it to the same file.


Thanks,
Nikita.

Answered by Media Engineer in 173744022

No, incorrect. You _never_ need to stop your capture session. The capture session automatically stops itself when your app goes to the background and resumes itself when you come back to the foreground.


Regarding NikitaCh's original questions:

iOS camera privacy policy dictates that no app is allowed to use the camera in the background. When your app goes to the background, your session will be interrupted. When it comes back, the interruption ends and the session preview resumes.


AVCaptureMovieFileOutput recordings that are in progress when you go to the background are stopped. AVCaptureMovieFileOutput does not support pause/resume. I suppose you should ask yourself if you want a single movie file that has a large time hole in it reflecting the time your app was in the background.


If you decide you absolutely do want this behavior, you can use AVCaptureVideoDataOutput and AVCaptureAudioDataOutput + AVAssetWriter to do your own recording.

Your app needs to stop the capture session when it loses focus and re-start it again upon entering the foreground.

Accepted Answer

No, incorrect. You _never_ need to stop your capture session. The capture session automatically stops itself when your app goes to the background and resumes itself when you come back to the foreground.


Regarding NikitaCh's original questions:

iOS camera privacy policy dictates that no app is allowed to use the camera in the background. When your app goes to the background, your session will be interrupted. When it comes back, the interruption ends and the session preview resumes.


AVCaptureMovieFileOutput recordings that are in progress when you go to the background are stopped. AVCaptureMovieFileOutput does not support pause/resume. I suppose you should ask yourself if you want a single movie file that has a large time hole in it reflecting the time your app was in the background.


If you decide you absolutely do want this behavior, you can use AVCaptureVideoDataOutput and AVCaptureAudioDataOutput + AVAssetWriter to do your own recording.

Thanks, that's good to know!

Thanks a lot.


Actually in my application i have two behaviours (regarding to app configuration). First is one movie file using AVCaptureMovieFileOutput and second - AVCaptureVideoDataOutput and AVCaptureAudioDataOutput + AVAssetWriter in separate files.


The thing that confuses me is that audio can be recorded in background but video no... Strange enough from my point of view, but anyway...
When i use AVAssetWriter i recieve same exception (AVFoundationErrorDomain Code = -11847 "Opetation Interrupted") even after returning to foreground. Should i manage interruption somehow? As i know AVAssetWriter have no pause too, i'm using boolean flags to manage pause (if flag is true i just skip writing data to file).


Am i missing something?


Thanks,
Nikita.

Audio recording in the backgrounded _is_ allowed on iOS. Different policy. When the microphone is in use and you press the home button (such as in Voice Memos), you see a red banner on top of the UI indicating that the mic is being used.


When using AssetWriter and getting -11847 on foregrounding, which API call is returning this error?

Can i continue record video when user put application on background mode?
 
 
Q