我使用 AndEngine 库创建了 android 动态壁纸应用程序。壁纸有一个带声音的摇摆动画。
问题是每次播放摆动声音时,摆动动画都会滞后几毫秒。
我想知道有没有解决方案?我曾尝试创建一个线程来播放声音,但结果仍然滞后。
代码是这样的...
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();
    }
}
如果您不了解 AndEngine,纯 openGL ES 解决方案也可以。