Android Guides | Samples

Android.Media.MediaRecorder Class

Used to record audio and video.

See Also: MediaRecorder

Syntax

[Android.Runtime.Register("android/media/MediaRecorder", DoNotGenerateAcw=true)]
public class MediaRecorder : Object

Remarks

Used to record audio and video. The recording control is based on a simple state machine (see below).

A common case of using MediaRecorder to record audio works as follows:

java Example

MediaRecorder recorder = new MediaRecorder();
 recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
 recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
 recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
 recorder.setOutputFile(PATH_NAME);
 recorder.prepare();
 recorder.start();   // Recording is now started
 ...
 recorder.stop();
 recorder.reset();   // You can reuse the object by going back to setAudioSource() step
 recorder.release(); // Now the object cannot be reused

Applications may want to register for informational and error events in order to be informed of some internal update and possible runtime errors during recording. Registration for such events is done by setting the appropriate listeners (via calls (to MediaRecorder.SetOnInfoListener(.IOnInfoListener)setOnInfoListener and/or MediaRecorder.SetOnErrorListener(.IOnErrorListener)setOnErrorListener). In order to receive the respective callback associated with these listeners, applications are required to create MediaRecorder objects on threads with a Looper running (the main UI thread by default already has a Looper running).

Note: Currently, MediaRecorder does not work on the emulator.

Developer Guides

For more information about how to use MediaRecorder for recording video, read the Camera developer guide. For more information about how to use MediaRecorder for recording sound, read the Audio Capture developer guide.

[Android Documentation]

Requirements

Namespace: Android.Media
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 1

The members of Android.Media.MediaRecorder are listed below.

See Also: Object

Public Constructors

Default constructor.

Protected Constructors

A constructor used when creating managed representations of JNI objects; called by the runtime.

Public Fields

const
MediaErrorServerDiedMediaRecorderError (100). Media server died.
const
MediaRecorderErrorUnknownMediaRecorderError (1). Unspecified media recorder error.

Public Properties

[read-only]
static
AudioSourceMaxInt32. Gets the maximum value for audio sources.
[read-only]
MaxAmplitudeInt32. Returns the maximum absolute amplitude that was sampled since the last call to this method.
[read-only]
SurfaceSurface. Gets the surface to record from when using SURFACE video source.

Protected Properties

[read-only]
override
ThresholdClassIntPtr. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.
[read-only]
override
ThresholdTypeType. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Public Methods

Prepare()
Prepares the recorder to begin capturing and encoding data.
Release()
Releases resources associated with this MediaRecorder object.
Reset()
Restarts the MediaRecorder to its idle state.
SetAudioChannels(Int32)
Sets the number of audio channels for recording.
SetAudioEncoder(AudioEncoder)
Sets the audio encoder to be used for recording.
SetAudioEncodingBitRate(Int32)
Sets the audio encoding bit rate for recording.
SetAudioSamplingRate(Int32)
Sets the audio sampling rate for recording.
SetAudioSource(AudioSource)
Sets the audio source to be used for recording.
SetAuxiliaryOutputFile(FileDescriptor)
SetAuxiliaryOutputFile(String)
SetCamera(Camera)
Sets a Camera to use for recording.
SetCaptureRate(Double)
Set video frame capture rate.
SetLocation(Single, Single)
Set and store the geodata (latitude and longitude) in the output file.
SetMaxDuration(Int32)
Sets the maximum duration (in ms) of the recording session.
SetMaxFileSize(Int64)
Sets the maximum filesize (in bytes) of the recording session.
SetOnErrorListener(MediaRecorder+IOnErrorListener)
Register a callback to be invoked when an error occurs while recording.
SetOnInfoListener(MediaRecorder+IOnInfoListener)
Register a callback to be invoked when an informational event occurs while recording.
SetOrientationHint(Int32)
Sets the orientation hint for output video playback.
SetOutputFile(FileDescriptor)
Pass in the file descriptor of the file to be written.
SetOutputFile(String)
Sets the path of the output file to be produced.
SetOutputFormat(OutputFormat)
Sets the format of the output file produced during recording.
SetPreviewDisplay(Surface)
Sets a Surface to show a preview of recorded media (video).
SetProfile(CamcorderProfile)
Uses the settings from a CamcorderProfile object for recording.
SetVideoEncoder(VideoEncoder)
Sets the video encoder to be used for recording.
SetVideoEncodingBitRate(Int32)
Sets the video encoding bit rate for recording.
SetVideoFrameRate(Int32)
Sets the frame rate of the video to be captured.
SetVideoSize(Int32, Int32)
Sets the width and height of the video to be captured.
SetVideoSource(VideoSource)
Sets the video source to be used for recording.
Start()
Begins capturing and encoding data to the file specified with setOutputFile().
Stop()
Stops recording.

Public Events