馬上加入Android 台灣中文網,立即免費下載應用遊戲。
您需要 登錄 才可以下載或查看,沒有帳號?註冊
x
我動用了postInvalidate()去刷新畫面制做了動畫
可是我希望在程式中能播放數秒音效配合動畫
音效程式碼在這:
static SoundPool sp;
static HashMap<Integer, Integer> map;
在onDraw()裡:
sp = new SoundPool(1, AudioManager.STREAM_MUSIC, 100);
map = new HashMap<Integer, Integer>();
map.put(R.raw.explosion, sp.load(context, R.raw.explosion, 1));
playSound(R.raw.explosion);
public static void playSound(int resId)
{
Integer soundId = map.get(resId);
if(soundId != null)
sp.play(R.raw.explosion, 1, 1, 1, 0, 1);
}
可是因為我每秒都會刷新(postInvalidate())
音效只播放1秒就會重新播放
有方法令音效獨立出來不受刷新影響嗎? |