在soundpool android中检查布尔值

时间:2015-08-18 21:56:30

标签: android soundpool

编辑:此代码如果加载soundpool声音设置布尔值为真。

log cat load 3声音但加载不正确。

<input type="radio" id="visitor" />Visitor
<input type="radio" id="ucstudent" />UC Student
<input type="radio" id="ucemployee" />UC Employee

永远不会加载== true。 如果清除此检查值,则播放声音。

1 个答案:

答案 0 :(得分:1)

试试这个:

public boolean loaded = false;
public SoundPool sp;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    sp = new SoundPool(3, AudioManager.STREAM_MUSIC, 0);
    sp.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
        @Override
        public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
            Log.i("OnLoadCompleteListener", "Sound " + sampleId + " loaded.");
            loaded=true;
        }
    });

    int sol = new int[3];
    sol[0] = sp.load(this, R.raw.x1, 1);
    sol[1] = sp.load(this, R.raw.x2, 1);
    sol[2] = sp.load(this,R.raw.x3, 1);

    //This 100 is the number of loops, I think it will be enough, but if
    //you want to set an infinite loop, you should better use MediaPlayer
    //then, but that will prevent you from playing many sounds together.
    sp.play(sol, 1.0f, 1.0f, 1, 100, 1.0f);

    if (loaded) {
        //I am not sure what's that method. It's yours...
        autosynce(sol);
    }
}