android video app time lapse
The android video app time lapse tutorial describes how to add record video in time lapse format.
In the android camera2 api video application we will be implementing a long click listener to be used for the time-lapse mode. Stopping time-lapse recording will be the same as recording, by just pressing the record button.
Get Code
The code to start this tutorial is on github here
https://github.com/mobapptuts/android_camera2_api_video_app.git Tag camera2-video-timelapse
or you can run this command
git clone https://github.com/mobapptuts/android_camera2_api_video_app.git –branch camera2-video-timelapse
Link to youtube tutorial describing how to do this using android studio
Steps
Add the images to the project
Add a flag to track the status of when the time-lapse is on
private boolean mIsTimelapse = false;
Add a long click listener to the record button
Where we will be changing the icon to time-lapse. We will also use the existing code to stop the time-lapse, the same as when we stop recording.
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_camera2_video_image); createVideoFolder(); createImageFolder(); mChronometer = (Chronometer) findViewById(R.id.chronometer); mTextureView = (TextureView) findViewById(R.id.textureView); mStillImageButton = (ImageButton) findViewById(R.id.cameraImageButton2); mStillImageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { lockFocus(); } }); mRecordImageButton = (ImageButton) findViewById(R.id.videoOnlineImageButton); mRecordImageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mIsRecording || mIsTimelapse) { mChronometer.stop(); mChronometer.setVisibility(View.INVISIBLE); mIsRecording = false; mIsTimelapse = false; mRecordImageButton.setImageResource(R.mipmap.btn_video_online); mMediaRecorder.stop(); mMediaRecorder.reset(); startPreview(); } else { mIsRecording = true; mRecordImageButton.setImageResource(R.mipmap.btn_video_busy); checkWriteStoragePermission(); } } }); mRecordImageButton.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { mIsTimelapse =true; mRecordImageButton.setImageResource(R.mipmap.btn_timelapse); checkWriteStoragePermission(); return true; } }); }
Create a method for setting up the time-lapse in the MediaRecorder
private void setupTimeLapse() throws IOException { mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE); mMediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_TIME_LAPSE_HIGH)); mMediaRecorder.setOutputFile(mVideoFileName); mMediaRecorder.setCaptureRate(2); mMediaRecorder.setOrientationHint(mTotalRotation); mMediaRecorder.prepare(); }
In the start record check whether to setup th MediaRecorder for recording or time-lapse
private void startRecord() { try { if(mIsRecording) { setupMediaRecorder(); } else if(mIsTimelapse) { setupTimeLapse(); }
Android video app time lapse summary
In the android video app time lapse tutorial we described the steps for how to setup time-lapse for the android camera2 api video application.
The steps involved
- Adding time-lapse icons to the project
- Adding a long click listener to the record button
- Setting up a status flag for the time-lapse mode
- Creating a method for configuring time-lapse in the MediaRecorder