Android Video Capture Example using Camera

Introduction:

If we want to use the inbuilt Camera of our device by your application then we have to initiate the Intent for it.By using android.provider.MediaStore class we can easily capture the video.The device Camera application requests video capture using android.provider.MediaStore.ACTION_VIDEO_CAPTURE.To launch the camera there is a need to initiate the intent by using startActivity(..) or startActivityForResult(..) method.

startActivityForResult():

Here, to access the captured video from a camera activity, the camera intent must be initiated using this call. It not only allows to start the camera application, but also one can also expect to get a result in form of a captured video.

To access the captured video we will override the callback method onActivityResult(…).Here we get the data and compare the request code, which is the second argument of the startActivityForResult() method, that the video has captured.

Example with Code:

Let’s see how we can create the Camera video capturing example by using startActivity() and startActivityForResult() method.

STEPS:

Create new Application CameraVideoCapturingExample.

AndroidManifest.xml:

First, we have to add some permissions to create the Camera application.Add this in your manifest file.

1st button is for capturing the video by expecting a result, which means it uses startActivityForResult().2nd button is for only capturing the video without accessing the video, which means it uses startActivity().3rd is to play the captured video. There is a condition that, if we capture the video by using startActivityForResult() then the play video button is enabled otherwise not.VideoView is used to play the video that has been captured.

MainActivity.java:

Here we will be using the VideoView object with Uri to play the captured video.

Add some code in onActivityResult() method:

Output:

Before Capture Video

After Capture Video

While Play Video

Conclusion:

This is the basic idea of how to create a similar camera application. We can customize it as per the need of the application and make it even better. It only shows how to launch the camera activity and get the data in return to capture the video. It finds usage in popular applications like Instagram. The camera functionality plays an important role in many applications and it is very popular in Android development.
Keep visiting our site www.acadgild.com for more updates on Android and other technologies.