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 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了.
阅读(2136) | 评论(0) | 转发(0) |