快速说明:我正在使用SoundPool类
http://developer.android.com/reference/android/media/SoundPool.html
我这里有一个简单的按钮,在按下时播放循环声音。它很棒。但是,sounds.autoPause();
直到API 8才被引入,我真的需要与蛋糕兼容的东西(API 3)所以我经历了由API 3过滤的开发参考站点,我看到暂停,所以我想我d尝试sounds.pause(sound);
但是当我释放它时它不会停止声音。(也许我只是错误地使用它?)有没有人知道一种蛋糕友好的方式来阻止这种声音?谢谢!
编辑:也尝试了sounds.stop(sound);
,但也无效。
守则:
我的onCreate:
sounds = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
sound = sounds.load(this.getApplicationContext(), R.raw.red_long_one, 1);
然后这是我的触摸事件
@Override public boolean onTouch(View arg0, MotionEvent event) {
switch (event.getAction() ) {
case MotionEvent.ACTION_DOWN:
System.out.println("touch");
sounds.play(sound, 1, 1, 1, -1, 1);
break;
case MotionEvent.ACTION_UP:
System.out.println("up");
//autoPause does not work on anything lower than sdk8
sounds.autoPause();
break;
}
return false;
}
我不明白为什么sounds.stop(sound);
似乎不起作用,这似乎只是我读过的任何文章建议做什么
我认为值得注意的是,如果我使用sounds.stop(sound);
它会工作一次,之后它就会在我放手后停止。但第一次按下并发布它按预期工作。
现在,我知道在andoird网站上它说的是streamID而不是soundID但我不知道如何获取streamID
答案 0 :(得分:1)
您需要使用streamID来停止声音。 playID由play()返回:
类似的东西:
//播放声音时记录streamid streamIDSoundFX = soundPool.play(soundFXPoolMap.get(ctSoundFX),streamVolume,streamVolume,1,0,1f);
//在需要时停止它 soundPool.stop(streamIDSoundFX);