Using Intents to Record Video

The easiest way to initiate video recording is using the ACTION_VIDEO_CAPTURE Media Store static constant in an Intent passed to startActivityForResult.

startActivityForResult(new Intent(MediaStore.ACTION_VIDEO_CAPTURE),

RECORD_VIDEO);

This will launch the native video camera Activity, allowing users to start, stop, review, and retake their video, and preventing you from having to rewrite the entire video camera application.

The video capture action supports two optional extras, available as static constants from the MediaStore class:

> extra_output By default, the video recorded by the video capture action will be stored in the default Media Store. If you want to record it elsewhere, you can specify an alternative URI using this extra.

> extra_video_quality The video record action allows you to specify an image quality using an integer value. There are currently two possible values: 0 for low (MMS) quality videos or 1 for high (full resolution) videos. By default, the high resolution mode will be used.

Listing 11-8 shows how to use the video capture action to record a new video in high quality to either a specified URI or the default media store.

LISTING 11-8: Recording video using an Intent

Available for download on Wrox.com private static int RECORD_VIDEO = 1; private static int HIGH_VIDEO_QUALITY = 1; private static int MMS_VIDEO_QUALITY = 0;

continues

LISTING 11-8 (continued)

private void recordVideo(Uri outputpath) {

Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);

intent.putExtra(MediaStore.EXTRA_OUTPUT, output); intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, HIGH_VIDEO_QUALITY);

startActivityForResult(intent, RECORD_VIDEO);

©Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == RECORD_VIDEO) { Uri recordedVideo = data.getData();

// TODO Do something with the recorded video

Mobile Apps Made Easy

Mobile Apps Made Easy

Quick start guide to skyrocket your offline and online business success with mobile apps. If you know anything about mobile devices, you’ve probably heard that famous phrase coined by one of the mobile device’s most prolific creators proclaiming that there’s an app for pretty much everything.

Get My Free Training Guide


Post a comment