MediaRecorder Class

Definition

Used to record audio and video.

[Android.Runtime.Register("android/media/MediaRecorder", DoNotGenerateAcw=true)]
public class MediaRecorder : Java.Lang.Object, Android.Media.IAudioRecordingMonitor, Android.Media.IAudioRouting, Android.Media.IMicrophoneDirection, IDisposable, Java.Interop.IJavaPeerable
[<Android.Runtime.Register("android/media/MediaRecorder", DoNotGenerateAcw=true)>]
type MediaRecorder = class
    inherit Object
    interface IAudioRecordingMonitor
    interface IJavaObject
    interface IDisposable
    interface IJavaPeerable
    interface IAudioRouting
    interface IMicrophoneDirection
Inheritance
MediaRecorder
Attributes
Implements

Remarks

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

<img src="https://developer.android.com/images/mediarecorder_state_diagram.gif" border="0" />

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

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 #setOnInfoListener(OnInfoListener)setOnInfoListener and/or #setOnErrorListener(OnErrorListener)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).

<strong>Note:</strong> Currently, MediaRecorder does not work on the emulator.

<div class="special reference"> <h3>Developer Guides</h3>

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.

</div>

Java documentation for android.media.MediaRecorder.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

MediaRecorder()

Default constructor.

MediaRecorder(Context)

Default constructor.

MediaRecorder(IntPtr, JniHandleOwnership)

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

Fields

MediaErrorServerDied
Obsolete.

Media server died.

MediaRecorderErrorUnknown
Obsolete.

Unspecified media recorder error.

Properties

ActiveMicrophones

Return A lists of MicrophoneInfo representing the active microphones.

ActiveRecordingConfiguration

Returns the current active audio recording for this audio recorder.

AudioSourceMax

Gets the maximum value for audio sources.

Class

Returns the runtime class of this Object.

(Inherited from Object)
Handle

The handle to the underlying Android instance.

(Inherited from Object)
JniIdentityHashCode (Inherited from Object)
JniPeerMembers
LogSessionId

Returns the LogSessionId for MediaRecorder. -or- Sets the LogSessionId for MediaRecorder.

MaxAmplitude

Returns the maximum absolute amplitude that was sampled since the last call to this method.

Metrics

Return Metrics data about the current Mediarecorder instance.

PeerReference (Inherited from Object)
PreferredDevice

Returns the selected input device specified by #setPreferredDevice.

PrivacySensitive

Returns whether this MediaRecorder is marked as privacy sensitive or not with regard to audio capture. -or- Indicates that this capture request is privacy sensitive and that any concurrent capture is not permitted.

RoutedDevice

Returns an AudioDeviceInfo identifying the current routing of this MediaRecorder Note: The query is only valid if the MediaRecorder is currently recording.

Surface

Gets the surface to record from when using SURFACE video source.

ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Methods

AddOnRoutingChangedListener(IAudioRoutingOnRoutingChangedListener, Handler)

Adds an AudioRouting.OnRoutingChangedListener to receive notifications of routing changes on this MediaRecorder.

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
Pause()

Pauses recording.

Prepare()

Prepares the recorder to begin capturing and encoding data.

RegisterAudioRecordingCallback(IExecutor, AudioManager+AudioRecordingCallback)

Register a callback to be notified of audio capture changes via a AudioManager.AudioRecordingCallback.

Release()

Releases resources associated with this MediaRecorder object.

RemoveOnRoutingChangedListener(IAudioRoutingOnRoutingChangedListener)

Removes an AudioRouting.OnRoutingChangedListener which has been previously added to receive rerouting notifications.

Reset()

Restarts the MediaRecorder to its idle state.

Resume()

Resumes recording.

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.

SetAudioProfile(EncoderProfiles+AudioProfile)

Uses the settings from an AudioProfile for recording.

SetAudioSamplingRate(Int32)

Sets the audio sampling rate for recording.

SetAudioSource(AudioSource)

Sets the audio source to be used for recording.

SetAuxiliaryOutputFile(FileDescriptor)
Obsolete.

Currently not implemented.

SetAuxiliaryOutputFile(String)
Obsolete.

Currently not implemented.

SetCamera(Camera)
Obsolete.

Sets a android.hardware.Camera to use for recording.

SetCaptureRate(Double)

Set video frame capture rate.

SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
SetInputSurface(Surface)

Configures the recorder to use a persistent surface when using SURFACE video source.

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.

SetNextOutputFile(File)

Sets the next output file to be used when the maximum filesize is reached on the prior output #setOutputFile or #setNextOutputFile).

SetNextOutputFile(FileDescriptor)

Sets the next output file descriptor to be used when the maximum filesize is reached on the prior output #setOutputFile or #setNextOutputFile).

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(File)

Pass in the file object to be written.

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.

SetPreferredDevice(AudioDeviceInfo)

Specifies an audio device (via an AudioDeviceInfo object) to route the input from this MediaRecorder.

SetPreferredMicrophoneDirection(MicDirection)

Specifies the logical microphone (for processing).

SetPreferredMicrophoneFieldDimension(Single)

Specifies the zoom factor (i.

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.

SetVideoEncodingProfileLevel(MediaCodecProfileType, Int32)

Sets the desired video encoding profile and level for recording.

SetVideoFrameRate(Int32)

Sets the frame rate of the video to be captured.

SetVideoProfile(EncoderProfiles+VideoProfile)

Uses the settings from a VideoProfile object for recording.

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.

ToArray<T>() (Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterAudioRecordingCallback(AudioManager+AudioRecordingCallback)

Unregister an audio recording callback previously registered with #registerAudioRecordingCallback(Executor, AudioManager.AudioRecordingCallback).

UnregisterFromRuntime() (Inherited from Object)
Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)

Events

Error
Info
RoutingChanged

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to