1.添加所需要的音頻庫頭文件。在frameworks/base/cmds/bootanimation/BootAnimation.h添加
#include <media/AudioSystem.h>
#include <media/mediaplayer.h>
2.在frameworks/base/cmds/bootanimation/BootAnimation.h中添加public方法:起名為bootMusic(),形式如下:
class BootAnimation : public Thread, public IBinder::DeathRecipient
{
public:
BootAnimation();
virtual ~BootAnimation(); sp<SurfaceComposerClient> session()const;
void bootMusic();
}
3.在frameworks/base/cmds/bootanimation/BootAnimation.cpp中添加bootMusic的實現方法:
void BootAnimation::bootMusic()
{
int index;
MediaPlayer* mp = new MediaPlayer();
if (mp->setDataSource("/system/etc/poweron.wav", NULL) == NO_ERROR) {
mp->setAudioStreamType(AUDIO_STREAM_ENFORCED_AUDIBLE);
mp->prepare();
}
AudioSystem::getStreamVolumeIndex(AUDIO_STREAM_ENFORCED_AUDIBLE, &index);
if (index != 0) {
mp->seekTo(0);
mp->start();
}
}
4.在frameworks/base/cmds/bootanimation/bootanimation_main.cpp中
在sp<BootAnimation> boot = new BootAnimation();與 IPCThreadState::self()->joinThreadPool();之間添加如下代碼:
sp<BootAnimation> boot = new BootAnimation();
BootAnimation *animation = new BootAnimation();
animation->bootMusic();
IPCThreadState::self()->joinThreadPool();
5.修改frameworks/base/cmds/bootanimation/Android.mk
在LOCAL_SHARED_LIBRARIES字段中添加libmedia共享庫
按照setDataSource("/system/etc/poweron.wav", NULL) == NO_ERROR) 裡所給的路徑和文件名添加相對應的名稱和音樂文件格式到指定的目錄就OK了.