1

第一次按下按钮停止声音。但在那之后按下它没有任何效果。这是我的java代码:

public class App extends MultiTouchActivity {

SoundPool sp;
    int  dub1s;

@Override
public void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub

    sp = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
     dub1s = sp.load(this, R.raw.dub1, 1);


}

public void dubstep1(View view) {

    sp.stop(dub1s);
    sp.play(dub1s, 1, 1, 1, 0, 1f);
}
4

1 回答 1

2

SoundPool.stop()获取流 id(来自 的返回值play),而不是声音 id(来自 的返回值load)。

他们不是一回事。

public class App extends MultiTouchActivity {

    SoundPool sp;
    int  mSoundId;
    int  mStreamId = 0;

@Override
public void onCreate(Bundle savedInstanceState) {
    sp = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
    mSoundId = sp.load(this, R.raw.dub1, 1);
}

public void dubstep1(View view) {
    if(mStreamId != 0) {
        sp.stop(mStreamId);
    }
    mStreamId = sp.play(mSoundId, 1, 1, 1, 0, 1f);
}
于 2012-10-22T20:41:08.473 回答