gpt4 book ai didi

android - SoundPool streamid

转载 作者:行者123 更新时间:2023-11-29 00:34:20 24 4
gpt4 key购买 nike

所以我有 soundpool OnLoadCompleteListener,它有这个代码 mStreamId = soundPool.play(sampleId, 1, 1, 1, 0, 1f);我有 2 个按钮可以播放不同的 soundpools。我使用 mStreamId 来停止 soundpool。我的问题是当我单击第一个按钮时它播放声音并且我单击第二个按钮它将停止第一个按钮的声音。这是我的代码:

    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);
}

最佳答案

soundId 和 streamId 分开保存。

onLoadComplete 在加载后调用,所以当您按下 button2 时,streamId 是 button1 播放的声音的 id。

关于android - SoundPool streamid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13479391/

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