Android多媒体框架初步分析
he 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. 我们可以看出MediaPlayer类提供了一个多媒体播放器的基本操作,播放,暂停,停止,设置音量等等。 简单的例子: Playing a File MediaPlayer mp = new MediaPlayer(); mp.setDataSource(PATH_TO_FILE); mp.prepare(); mp.start(); Playing a Raw Resource MediaPlayer mp = MediaPlayer.create(context, R.raw.sound_file_1); mp.start(); Media Recorder 提供的基本接口如下: Public 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 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. 简单的例子: 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 整体的结构如下图所示: l MediaPlayer JNI 代码位置 /frameworks/base/media/jni l MediaPlayer (Native) 代码位置 /frameworks/base/media/libmedia l MediaPlayerService (Server) 代码位置 /frameworks/base/media/libmediaplayerservice l MediaPlayerService Host Process 代码位置 /frameworks/base/media/mediaserver/main_mediaserver.cpp l PVPlayer 代码位置 /external/opencore/android/ 实际调用过程如下图所示:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)