Android
android.media
public class

android.media.MediaRecorder

java.lang.Object
android.media.MediaRecorder

Used to record audio and video. See the Android Media APIs page for help using using MediaRecorder.

Nested Classes

Summary

Public Constructors

            MediaRecorder()
Default constructor.

Public Methods

          int  getMaxAmplitude()
Returns the maximum absolute amplitude that was sampled since the last call to this method.
          void  prepare()
Prepares the recorder to begin capturing and encoding data.
          void  release()
Releases resources associated with this MediaRecorder object.
          void  reset()
Restarts the MediaRecorder to its uninitialized state.
          void  setAudioEncoder(int audio_encoder)
Sets the audio encoder to be used for recording.
          void  setAudioSource(int audio_source)
Sets the audio source to be used for recording.
          void  setOutputFile(String path)
Sets the path of the output file to be produced.
          void  setOutputFormat(int output_format)
Sets the format of the output file produced during recording.
          void  setPreviewDisplay(Surface sv)
Sets a Surface to show a preview of recorded media (video).
          void  setVideoEncoder(int video_encoder)
Sets the video encoder to be used for recording.
          void  setVideoFrameRate(int rate)
Sets the frame rate of the video to be captured.
          void  setVideoSize(int width, int height)
Sets the width and height of the video to be captured.
          void  setVideoSource(int video_source)
Sets the video source to be used for recording.
          void  start()
Begins capturing and encoding data to the file specified with setOutputFile().
          void  stop()
Stops recording.

Protected Methods

          void  finalize()
Called by the virtual machine when there are no longer any (non-weak) references to the receiver.
Methods inherited from class java.lang.Object

Details

Public Constructors

public MediaRecorder()

Default constructor.

Public Methods

public int getMaxAmplitude()

Returns the maximum absolute amplitude that was sampled since the last call to this method. Call this only after the audio source has been set.

Returns

  • the maximum absolute amplitude measured since the last call, or 0 when called for the first time

Throws

IllegalStateException if it is called before the audio source has been set.

public void prepare()

Prepares the recorder to begin capturing and encoding data. This method must be called after setting up the desired audio and video sources, encoders, file format, etc., and before start().

Throws

IllegalStateException if it is called after start() or before setOutputFormat().

public void release()

Releases resources associated with this MediaRecorder object. It is good practice to call this method when you're done using the MediaRecorder.

public void reset()

Restarts the MediaRecorder to its uninitialized state. After calling this method, you will have to initialize it again as if it had just been constructed.

public void setAudioEncoder(int audio_encoder)

Sets the audio encoder to be used for recording. If this method is not called, the output file will not contain an audio track. Call this after setOutputFormat() and before prepare().

Parameters

audio_encoder the audio encoder to use.

Throws

IllegalStateException if it is called before setOutputFormat() or after prepare().

public void setAudioSource(int audio_source)

Sets the audio source to be used for recording. If this method is not called, the output file will not contain an audio track. The source needs to be specified before setting recording-parameters or encoders. Call this only before setOutputFormat().

Parameters

audio_source the audio source to use

Throws

IllegalStateException if it is called after setOutputFormat()

public void setOutputFile(String path)

Sets the path of the output file to be produced. Call this after setOutputFormat() and before prepare().

Parameters

path The pathname to use()

Throws

IllegalStateException if it is called before setOutputFormat() or after prepare()

public void setOutputFormat(int output_format)

Sets the format of the output file produced during recording. Call this before prepare().

Parameters

output_format the output format to use. The output format needs to be specified before setting recording-parameters or encoders.

Throws

IllegalStateException if it is called after prepare().

public void setPreviewDisplay(Surface sv)

Sets a Surface to show a preview of recorded media (video).

Parameters

sv the Surface to use for the preview

public void setVideoEncoder(int video_encoder)

Sets the video encoder to be used for recording. If this method is not called, the output file will not contain an video track. Call this after setOutputFormat() and before prepare().

Parameters

video_encoder the video encoder to use.

Throws

IllegalStateException if it is called before setOutputFormat() or after prepare()

public void setVideoFrameRate(int rate)

Sets the frame rate of the video to be captured. Must be called after setVideoSource(). Call this after setOutFormat() but before prepare().

Parameters

rate the number of frames per second of video to capture

Throws

IllegalStateException if it is called after prepare() or before setOutputFormat().

public void setVideoSize(int width, int height)

Sets the width and height of the video to be captured. Must be called after setVideoSource(). Call this after setOutFormat() but before prepare().

Parameters

width the width of the video to be captured
height the height of the video to be captured

Throws

IllegalStateException if it is called after prepare() or before setOutputFormat()

public void setVideoSource(int video_source)

Sets the video source to be used for recording. If this method is not called, the output file will not contain an video track. The source needs to be specified before setting recording-parameters or encoders. Call this only before setOutputFormat().

Parameters

video_source the video source to use

Throws

IllegalStateException if it is called after setOutputFormat

public void start()

Begins capturing and encoding data to the file specified with setOutputFile(). Call this after prepare().

Throws

IllegalStateException if it is called before prepare().

public void stop()

Stops recording. Call this after start().

Throws

IllegalStateException if it is called before start()

Protected Methods

protected void finalize()

Called by the virtual machine when there are no longer any (non-weak) references to the receiver. Subclasses can use this facility to guarantee that any associated resources are cleaned up before the receiver is garbage collected. Uncaught exceptions which are thrown during the running of the method cause it to terminate immediately, but are otherwise ignored.

Note: The virtual machine assumes that the implementation in class Object is empty.

Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:48