新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > Android多媒體框架初步分析

Android多媒體框架初步分析

作者: 時(shí)間:2016-10-08 來源:網(wǎng)絡(luò) 收藏

void stop()

Stops playback after playback has been stopped or paused.

我們可以看出MediaPlayer類提供了一個(gè)多媒體播放器的基本操作,播放,暫停,停止,設(shè)置音量等等。

簡(jiǎn)單的例子:

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.

簡(jiǎn)單的例子:

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

整體的結(jié)構(gòu)如下圖所示:

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/

實(shí)際調(diào)用過程如下圖所示:


上一頁 1 2 下一頁

關(guān)鍵詞:

評(píng)論


相關(guān)推薦

技術(shù)專區(qū)

關(guān)閉