的Soundpool站只有一次 [英] SoundPool stops only once
本文介绍了的Soundpool站只有一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
pressing按钮在第一时间停止的声音。但是,$ P $后pssing它不会有任何影响。这是我的Java code:
公共类应用扩展MultiTouchActivity {
的Soundpool SP;
诠释dub1s;
@覆盖
公共无效的onCreate(包savedInstanceState){
// TODO自动生成方法存根
SP =新的Soundpool(5,AudioManager.STREAM_MUSIC,0);
dub1s = sp.load(此,R.raw.dub1,1);
}
公共无效dubstep1(查看视图){
sp.stop(dub1s);
sp.play(dub1s,1,1,1,0,1F);
}
解决方案
SoundPool.stop()
取流ID (返回从价值播放
),而不是在声音ID (返回从值负荷
)
他们是不一样的东西。
公共类应用扩展MultiTouchActivity {
的Soundpool SP;
INT mSoundId;
INT mStreamId = 0;
@覆盖
公共无效的onCreate(包savedInstanceState){
SP =新的Soundpool(5,AudioManager.STREAM_MUSIC,0);
mSoundId = sp.load(此,R.raw.dub1,1);
}
公共无效dubstep1(查看视图){
如果(mStreamId!= 0){
sp.stop(mStreamId);
}
mStreamId = sp.play(mSoundId,1,1,1,0,1楼);
}
Pressing the button the first time stops Sound. But pressing it after that does not have any effect. This is my java code:
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()
takes the stream id (return value from play
), not the sound id (return value from load
).
They aren't the same thing.
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);
}
这篇关于的Soundpool站只有一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文