我有一个带有一些声音效果的按钮。当我单击按钮时,什么也没有发生。没有声音播放,但也没有力量关闭。调试器给我这个警告:
“ SoundPool-示例1尚未就绪”
“ SoundPool-Sample 2 not READY”等...
密码:
package com.andrew.finnandjake;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class Soundboard extends Activity{
private SoundManager mSoundManager;
private int next = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mSoundManager = new SoundManager();
mSoundManager.initSounds(getBaseContext());
mSoundManager.addSound(0,R.raw.finn_algebraic);
mSoundManager.addSound(1,R.raw.finn_allaboardthekuckletrain);
mSoundManager.addSound(2,R.raw.finn_iminmyelement);
mSoundManager.addSound(3,R.raw.finn_shmowzow);
Button SoundButton=(Button)findViewById(R.id.Button1);
SoundButton.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v){
mSoundManager.playSound(next);
next++;
if(next>3)
next=0;
}
});
}
}
最佳答案
加载声音需要一段时间。您可以使用SoundPool.OnLoadCompleteListener
找出它们何时准备就绪。 (仅限Android 2.2以上版本)