gpt4 book ai didi

java - SoundPool 只停止一次

转载 作者:行者123 更新时间:2023-11-29 21:56:51 29 4
gpt4 key购买 nike

第一次按下按钮停止声音。但是在那之后按下它没有任何效果。这是我的 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);
}

最佳答案

SoundPool.stop() 采用流 ID(播放 的返回值),而不是声音 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);
}

关于java - SoundPool 只停止一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13019438/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com