我有一个带有一些声音效果的按钮。当我点击按钮时,没有任何反应。没有声音播放,但也没有声音关闭。调试器给了我这个警告:
“SoundPool - 示例1未准备就绪” “SoundPool - 样本2未准备就绪”等...
Le Code:
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;
}
});
}
}
答案 0 :(得分:3)
声音需要一段时间才能加载。您可以使用SoundPool.OnLoadCompleteListener
查看它们何时准备就绪。 (仅限Android 2.2+)