所以我有soundpool OnLoadCompleteListener,它的代码是mStreamId = soundPool.play(sampleId,1,1,1,0,1f);我有两个按钮,可以播放不同的音池。我使用mStreamId来停止soundpool.My的问题是,当我点击第一个按钮时,它会播放声音,我点击第二个按钮,它会停止第一个按钮的声音。下面是我的代码:
public class MainActivity extends Settings {
SoundPool mSoundPool;
int mSoundId;
int mStreamId = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
mSoundPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
mSoundPool
.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
public void onLoadComplete(SoundPool soundPool,
int sampleId, int status) {
mStreamId = soundPool.play(sampleId, 1, 1, 1, 0, 1f);
}
});
}
//OnClick
public void button1(View view) {
if (mStreamId != 0) {
mSoundPool.stop(mStreamId);
}
String path = getFullFilePath(getApplicationContext(), et1.getText()
.toString());
mSoundId = mSoundPool.load(path, 1);
}
public void button2(View view) {
if (mStreamId != 0) {
mSoundPool.stop(mStreamId);
}
String path = getFullFilePath(getApplicationContext(), et2.getText()
.toString());
mSoundId = mSoundPool.load(path, 1);
}发布于 2013-10-05 12:15:19
因为你让它这么做的。如果希望声音播放到结束,请删除stop方法调用。播放声音时,Soundpool将返回池中的下一个可用流。
https://stackoverflow.com/questions/13518399
复制相似问题