I created android live wallpaper application using AndEngine library. The wallpaper has a swing animation with sound.
The problem is everytime the swinging sound plays, the swing animation become lagged for few milliseconds.
I want to know is there a solution for this? I had tried by creating a thread for playing the sound, but the result was still lagged too.
The code is like this…
public class TreeSwingSprite extends AnimatedSprite
implements IAnimationListener, IEntityModifierListener {
...
private Sound swingSound;
// this event happened when user touch the Sprite on screen
public boolean onAreaTouched(TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {
if (pSceneTouchEvent.isActionDown()) {
...
long[] frameDuration = new long[] {
50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
...
};
final int[] frame = {
10, 9, 8, 7, 6, 5, 4, 3, 2, 1,
...
};
animate(frameDuration, frame, 0, this); // this code execute the animation of the Sprite
// play the sound
new Thread(new Runnable() {
@Override
public void run() {
if (swingSound != null) swingSound.play();
}
}).start();
}
}
If you don’t know AndEngine, pure openGL ES solution is okay too.
Nevermind, the cause of lag is the particular device doesn’t have strong hardware support, probably the processor. I know that because when I tried with other device, it run fine.