Using the Media Recorder


Build your own Android App Dev Empire

Get Instant Access

Multimedia recording is handled by the aptly named MediaRecorder class. You can use it to record audio and/or video files that can be used in your own applications, or added to the Media Store.

To record audio or video, create a new Media Recorder object.

MediaRecorder mediaRecorder = new MediaRecorder();

Before you can record any media in Android, your application needs the record_audio and / or record_video permissions. Add uses-permission tags for each of them, as required, in your application manifest.

<uses-permission android:name="android.permission.RECORD_AUDIO"/> <uses-permission android:name="android.permission.RECORD_VIDEO"/>

The Media Recorder lets you specify the audio and video source, the output file format, and the audio and video encoders to use when recording your file.

Much like the Media Player, the Media Recorder manages recording as a state machine. That means that the order in which you configure and manage the Media Recorder is important.

In the simplest terms, the transitions through the state machine can be described as follows:

> Create a new Media Recorder.

> Assign it the input sources to record from.

> Define the output format.

> Specify the audio and video encoder, frame rate, and output size.

> Select an output file.

> Prepare for recording.

> End recording.

A more detailed and thorough description of the Media Recorder state machine is provided at the Android developer site at .html

Once you've finished recording your media, calkelease on your Media Recorder object to free the associated resources.


Was this article helpful?

0 0
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