多媒体框架层
多媒体框架层Android中间层,也是Java SDK层。向下通过JNI负责封装OpenCore,向上负责为多媒体应用程序提供Java接口。所有的多媒体相关的类和接口都包含在 android.media这个package当中,包括 AudioFormat,AudioManager,AudioTrack,MediaPlayer,MediaRecorder, Ringtone, RingtoneManager等等。其中MediaPlayer和MediaRecorder是最为主要的两个类。
MediaPlayer主要接口
提供了一个多媒体播放器常用的基本操作如播放,暂停,停止,获取文件播放长度,Seek 等等。
static MediaPlayer create(Context context, Uri uri)
Convenience method to create a MediaPlayer for a given Uri.
int getCurrentPosition()
Gets the current playback position.
int getDuration()
Gets the duration of the file.
int getVideoHeight()
Returns the height of the video.
int getVideoWidth()
Returns the width of the video.
boolean isPlaying()
Checks whether the MediaPlayer is playing.
void pause()
Pauses playback.
void prepare()
Prepares the player for playback, synchronously.
void prepareAsync()
Prepares the player for playback, asynchronously.
void release()
Releases resources associated with this MediaPlayer object.
void reset()
Resets the MediaPlayer to its uninitialized state.
void seekTo(int msec)
Seeks to specified time position.
void setAudioStreamType(int streamtype)
Sets the audio stream type for this MediaPlayer.
void setDataSource(String path)
Sets the data source (file-path or http/rtsp URL) to use.
void setDisplay(SurfaceHolder sh)
Sets the SurfaceHolder to use for displaying the video portion of the media.
void setVolume(float leftVolume, float rightVolume)
Sets the volume on this player.
void start()
Starts or resumes playback.
void stop()
Stops playback after playback has been stopped or paused.
MediaRecorder主要接口
提供了声音录制的基本功能。
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 idle 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 start()
Begins capturing and encoding data to the file specified with setOutputFile().
void stop()
Stops recording.
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 idle 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 start()
Begins capturing and encoding data to the file specified with setOutputFile().
void stop()
Stops recording.