To solve the problem, we can apply the service for the video recording. When the video recorder is starting with a service, the video recorder can be run in the background. In that case, you can keep to record the video screen even though you are accessing other application.
This article shows an example for making video record as a service on Android.
1. First of all, you have to create a Android project for developing the video recorder application.
2. Initialize the camera and media record instances.
3. For starting the Service, you have to new an Intent instance to indicate which the service you want to start.
Indicate the source activity and the target service in intent variable.
The Intent.FLAG_ACTIVITY_NEW_TASK is set for intent to indicate the activity will become a new task.
When the service will be started, the first activity has to be closed. So we call the finish() to close the activity.
Intent intent = new Intent(CameraRecorder.this, RecorderService.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startService(intent); finish();
4. You can reference to the Android SDK website: MediaRecorder for recording the video.
You have to follow the steps of MediaRecorder.
You can reference this code.
mMediaRecorder = new MediaRecorder(); mMediaRecorder.setCamera(mServiceCamera); mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT); mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT); mMediaRecorder.setOutputFile("/sdcard/video.mp4"); mMediaRecorder.setVideoFrameRate(30); mMediaRecorder.setVideoSize(mPreviewSize.width, mPreviewSize.height); mMediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface()); mMediaRecorder.prepare(); mMediaRecorder.start();
The sample project implements a service for video recording is uploaded to the Github. You can find out the repository and download it from this link: CameraRecorder in Github.