Android4.0.3 modify startup animation and boot sound

Source: Internet
Author: User

1. When the Linux system is started, the Linux little penguin screen (reboot) appears (Android 1.5 and later versions have canceled image loading );
2. The Android platform starts initialization and displays the text "a n d r I O D;
3. The Graphic System of the Android platform is started, and an animated image (start) containing the flashing Android text is displayed ).

Now we are talking about the third method (based on simulators ):

The android boot animation source code is located in frameworks/base/cmds/bootanimation, this program will play the PNG Image in/data/local/bootanimation.zip or/system/Media/bootanimation.zip in an animation.

First, let's analyze the source code:

Frameworks/base/cmds/bootanimation. cpp

First, let's take a look at the defined constants:

#define USER_BOOTANIMATION_FILE "/data/local/bootanimation.zip"#define SYSTEM_BOOTANIMATION_FILE "/system/media/bootanimation.zip"#define SYSTEM_ENCRYPTED_BOOTANIMATION_FILE "/system/media/bootanimation-encrypted.zip"

Bootanimation: readytorun ()

Enter an if judgment statement

if ((encryptedAnimation &&            (access(SYSTEM_ENCRYPTED_BOOTANIMATION_FILE, R_OK) == 0) &&            (mZip.open(SYSTEM_ENCRYPTED_BOOTANIMATION_FILE) == NO_ERROR)) ||            ((access(USER_BOOTANIMATION_FILE, R_OK) == 0) &&            (mZip.open(USER_BOOTANIMATION_FILE) == NO_ERROR)) ||            ((access(SYSTEM_BOOTANIMATION_FILE, R_OK) == 0) &&            (mZip.open(SYSTEM_BOOTANIMATION_FILE) == NO_ERROR))) {        mAndroidAnimation = false;    }

Bootanimation: threadloop ()

If (mandroidanimation) {r = Android (); // execute the android font flashing image} else {r = movie (); // execute the animated image provided in bootanimation.zip}
 

==> Bootanimation: Android () loads "images/android-logo-mask.png" and "images/android-logo-shine.png"
==> Bootanimation: movie()) content in bootanimation.zip

There are no. Zip animations in the downloaded source code, so they will always jump to the android font flashing screen.

If you use the. Zip animation, copy the prepared animation to the compiled directory. Then, execute make Snod and integrate it into the IMG package to see the effect.

If you want to modify the two Android flash images, the easiest way is to directly replace the images. If you know OpenGL, you can also make their own cool animations.

Put the two images in. in the/frameworks/base/CORE/RES/assets/images directory, a hollow Android image shows a luminous effect, and the animation effect is that the light is constantly moving around.

I directly modified it using Photoshop.

Replace it directly after modification, and then use Mmm frameworks/base and make Snod.

The following is my modified one:

 

It seems like you still want to do that.

Next, we will add a boot sound to the system.

Because the animation is played in bootanimation, our sound must be in this category.

First, add the method declaration and reference of the header file in bootanimation. h.

#include <media/AudioSystem.h>#include <media/mediaplayer.h>

 

Add method void bootmusic ();

Then implement this method in bootanimation. cpp:

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();    }}

Please note that this directory setdatasource ("/system/etc/poweron.wav", null)

In fact, this directory is written at will. You can read this file from which directory you want to read it from, but you need to put this file under the corresponding directory.

For example, this directory is system/etc (this directory is the directory of the Android system, not the source code directory). This folder has only the read permission but has no write permission, you don't need to try ADB shell anymore. It's useless.

In fact, the system/etc directory corresponds to XXX in the out folder after compilation, and you can put poweron.wav here in system/etc, of course, if you try emulaor again, you will not be able to see the effect, because you have not compiled the modification, just like the picture above, make Snod it.

Then, as shown in the figure below, you will generate a new system.img. of course, the previous poweron.wav will also be automatically compiled.

 

Then modify the bootanimation_main.cpp file, because the method is also declared and implemented, that is, it has not been called, so the call is called here

 

//play boot music -yp        BootAnimation *animation = new BootAnimation();        animation->bootMusic();

 

After the modification, You need to modify the Android. mk file.

Because the playback sound needs to be imported into the database

Local_shared_libraries: = \
Libcutils \
Libutils \
Libbinder \
Libui \
Libskia \
Libegl \
Libglesv1_cm \
Libgui \
Libmedia

 

Please note that libmedia is newly added;

It will be OK after completion, of course it still needs to be compiled

Mmm frameworks/base/cmds/bootanimation/

Make Snod

 

You have successfully added the boot music.

Some may ask, where are the music and ringtones of the Android system?

The source code directory is in framworks/base/data/sounds.

Where can I put the compilation? It is configured on the Android. mk file.

But this is called allaudio. mk.

We can see that it contains many MK files, which can be found in the same directory.

 

Now you can understand that all these resources have gone to Shenma after compilation.

 

All in all, when we are just getting poweron.wav, we can actually directly drop the sound resources to the framworks/base/data/sounds directory.

Then modify the settings in the MK file as follows:

$ (Local_path)/poweron.wav: System/etc/poweron.wav \

 

I don't need to say that, of course, the mmm And make Snod commands are executed.

 

There is also a way to do this. If you don't want to worry about it, how can you use it to throw the poweron.wav file to./frameworks/base/CORE/RES/assets/sounds?

What is the path when loading? Let's look at the source code

We can see how the two images we modified were loaded.

The two parameters of this method are:

Did you understand it again?

The original essence is that there is an asset that can be used. This is the same as that in upper-layer development, and the content in this folder is not compiled.

Asset* asset = assets.open(name, Asset::ACCESS_BUFFER);    if (!asset)        return NO_INIT;    SkBitmap bitmap;    SkImageDecoder::DecodeMemory(asset->getBuffer(false), asset->getLength(),            &bitmap, SkBitmap::kNo_Config, SkImageDecoder::kDecodePixels_Mode);    asset->close();    delete asset;

 

Click this example to find the poweron.wav file, and then modify the bootmusic code.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.