标签: 视频动画mediaplayerframeworksbootanimation
2014-11-12 14:18
672人阅读
收藏
举报
原创文章,转载请注明出处,谢谢。
一,前言
对于开机动画的实现原理,网上很多,本文不做讲述。本文仅针对开关机动画支持Mp4视频及实现关机动画做简略讲述
二,前期准备及说明
开机动画MP4视频文件名及路径:/system/media/boot.mp4、/data/local/boot.mp4
关机动画MP4视频文件名及路径:/system/media/shutdown.mp4、/data/local/shutdown.mp4
三,需要修改的文件
1.开机动画的MP4视频支持
frameworks/base/cmds/bootanimation/BootAnimation.cpp
frameworks/base/cmds/bootanimation/BootAnimation.h
frameworks/base/cmds/bootanimation/Android.mk
2.关机动画实现
frameworks/base/cmds/bootanimation/BootAnimation.cpp
frameworks/base/cmds/bootanimation/bootanimation_main.cpp。
ShutdownThread.java
init.rc
四,具体修改
播放MP4格式支持较为简单,主要是在
frameworks/base/cmds/bootanimation/BootAnimation.cpp添加video()方法并在readytorun判断文件是否存在,并在threadloop判断是否进入video()方法。
video方法代码如下
[cpp] view plain copy print ?
- bool BootAnimation::video()
- {
- const float MAX_FPS = 60.0f;
- const bool LOOP = true;
- const float CHECK_DELAY = ns2us(s2ns(1) / MAX_FPS);
-
- eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
- eglDestroySurface(mDisplay, mSurface);
- #if 0
- float asp = 1.0f * mWidth / mHeight;
- SurfaceComposerClient::openGlobalTransaction();
- mFlingerSurfaceControl->setPosition(mWidth, 0);
- mFlingerSurfaceControl->setMatrix(0, 1 / asp, -asp, 0);
- SurfaceComposerClient::closeGlobalTransaction();
- #endif
- sp<MediaPlayer> mp = new MediaPlayer();
- mp->reset();
- if(!mShutdown) {
- if(systemfile) {
- mp->setDataSource(USER_BOOTVIDEO_FILE, NULL);
- } else {
- mp->setDataSource(SYSTEM_BOOTVIDEO_FILE, NULL);
- }
- } else {
- if(systemfile) {
- mp->setDataSource(USER_SHUTDOWN_VIDEO, NULL);
- } else {
- mp->setDataSource(SYSTEM_SHUTDOWN_VIDEO, NULL);
- }
- }
- mp->setLooping(false);
- Parcel* _parcel = new Parcel;
- mp->setParameter(100, *_parcel);
- mp->setVideoSurfaceTexture(mFlingerSurface->getIGraphicBufferProducer());
- mp->prepare();
- mp->start();
- #if 1
- while(true) {
- if(exitPending())
- break;
- usleep(CHECK_DELAY);
- checkExit();
- }
- #endif
- mp->stop();
- return false;
- }
关机动画实现 需要修改init.rc 添加如下服务
service shutdownanim /system/bin/bootanimation -shutdown
user graphics
group graphics
ShutdownThread.java修改beginShutdownSequence方法把如下代码注释掉
[java] view plain copy print ?
- ProgressDialog pd = new ProgressDialog(context);
- pd.setTitle(context.getText(com.android.internal.R.string.power_off));
- pd.setMessage(context.getText(com.android.internal.R.string.shutdown_progress));
- pd.setIndeterminate(true);
- pd.setCancelable(false);
- pd.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
-
- pd.show();
并添加android.os.SystemProperties.set("ctl.start", "shutdownanim");即可
最后重新编译boot及boota 重启即可