Can't continue recording video when pressing home button on Android
I am trying to develop an android app that interacts with Camera hardware to record video. It records a video for 10 seconds, saves it and sends it to the server (in a background thread) and starts another video within the next 10 seconds. It is expected to shoot videos indefinitely unless the user clicks the stop button in the app. Even if the user presses the home button, then the video recording must continue in the background .
Currently, if the user clicks the home button, the camera view throws an exception like "Java: IO exception: Invalid preview surface"
Here is a piece of code that I used
recorder.setOutputFile(outputFile+"_"+number+".mp4");
recorder.setPreviewDisplay( holder.getSurface());
if (recorder != null) {
try {
recorder.prepare();
recorder.start();
} catch (IllegalStateException e) {
Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
}
}
Is it possible to continue recording in the background even when the user clicks on the master key?
+3
source to share