https://github.com/zytc2009/BigTeam_learning
分类: Java
2010-11-20 16:38:02
1. 音频播放
示例代码
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(PATH_TO_FILE);
mp.prepare();
mp.start();
1.1 MediaPlayer mp = new MediaPlayer()
函数调用 |
文件 |
MediaPlayer:: MediaPlayer |
MediaPlayer.Java |
MediaPlayer::native_setup |
MediaPlayer.Java |
android_media_MediaPlayer_native_setup |
android_media_MediaPlayer.cpp |
MediaPlayer::MediaPlayer |
MediaPlayer.cpp |
1.2 mp.setDataSource(PATH_TO_FILE)
函数调用 |
文件 |
MediaPlayer:: setDataSource |
MediaPlayer.Java |
MediaPlayer::setDataSource |
MediaPlayer.Java |
android_media_MediaPlayer_setDataSource |
android_media_MediaPlayer.cpp |
MediaPlayer:: setDataSource |
MediaPlayer.cpp |
MediaPlayer::getMediaPlayerService |
MediaPlayer.cpp |
IMediaPlayerService |
IMediaPlayerService.h |
MediaPlayerService:: [f1] |
MediaPlayerService.cpp |
MediaPlayerService::create |
MediaPlayerService.cpp |
MediaPlayerService::Client::Client |
MediaPlayerService.cpp |
MediaPlayerService::Client::setDataSource |
MediaPlayerService.cpp |
MediaPlayerService.cpp |
|
MediaPlayerService::Client::createPlayer |
MediaPlayerService.cpp |
createPlayer |
MediaPlayerService.cpp |
PVPlayer |
PVPlayer.h |
MidiFile |
MidiFile.cpp |
VorbisPlayer |
VorbisPlayer.cpp |
AudioOutput::AudioOutput |
MediaPlayerService.cpp |
1.3 mp.prepare()
函数调用 |
文件 |
MediaPlayer:: prepare |
MediaPlayer.Java |
MediaPlayer:: prepare |
MediaPlayer.Java |
android_media_MediaPlayer_ prepare |
android_media_MediaPlayer.cpp |
MediaPlayer:: prepare |
MediaPlayer.cpp |
PVPlayer:: prepare |
PVPlayer.h |
MidiFile:: prepare |
MidiFile.cpp |
VorbisPlayer:: prepare |
VorbisPlayer.cpp |
VorbisPlayer::createOutputTrack |
VorbisPlayer.cpp |
AudioOutput::open |
MediaPlayerService.cpp |
AudioTrack::AudioTrack |
AudioTrack.cpp |
AudioSystem::get_audio_flinger |
AudioSystem.cpp |
AudioFlinger::createTrack |
AudioFlinger.cpp |
1.4 mp.start()
函数调用 |
文件 |
MediaPlayer:: start |
MediaPlayer.Java |
MediaPlayer:: start |
MediaPlayer.Java |
android_media_MediaPlayer_ start |
android_media_MediaPlayer.cpp |
MediaPlayer:: start |
MediaPlayer.cpp |
PVPlayer:: start |
PVPlayer.h |
MidiFile:: p start |
MidiFile.cpp |
VorbisPlayer:: start |
VorbisPlayer.cpp |
AudioTrack::start |
AudioTrack.cpp |
[f1]由systemserver进程创建,在文件system_init.cpp里的函数system_init()调用MediaPlayerService::instantiate创建
[f2]返回3种player
PV_PLAYER:播放mp3
SONIVOX_PLAYER:播放midi
VORBIS_PLAYER:播放ogg,
简单说来,轨迹如下:
Java端发起调用,MediaPlayer会转至MediaPlayerService, 然后会调用相应的解码工具解码后创建AudioTrack,所有待输出的AudioTrack在AudioFlinger::AudioMixer里合 成,然后通过AudioHAL(AudioHardwareInterface的实际实现者)传至实际的硬件来实现播放