Seekbar 控制 Soundpool,停止工作

Seekbar Controlling Soundpool, stops working

所以我有 8 张图像,每张图像开始一个 8 种不同声音的循环。我在每个图像下方都有一个搜索栏来控制该声音的音量。

搜索栏在第一次播放声音时工作正常,但当停止并再次播放时,搜索栏不再控制音量。我究竟做错了什么? `noiseVolumeControl.setOnSeekBarChangeListener(新SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            double noiseVol = (double) progress / (double) maxVolume;

            Log.i("Noise Volume", String.valueOf(progress) + " " + String.valueOf((float) noiseVol));
            mySound.setVolume(whiteNoiseId, (float) noiseVol, (float) noiseVol);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });

public void whiteNoiseTapped(View view) {

    Log.i("White Noise", "button tapped");

    if (whiteNoisePlaying) {
        Log.i("White Noise", "already playing");
        mySound.stop(noiseStreaming);
        whiteNoisePlaying = false;
        ((ImageView) view).setImageResource(R.drawable.whitenoise);
        isPlaying--;
    } else if (isPlaying < 3) {
        Log.i("White Noise", "start playing");
        noiseStreaming = mySound.play(whiteNoiseId, (float) noiseVol, (float) noiseVol, 1, -1, 1);
        whiteNoisePlaying = true;
        ((ImageView) view).setImageResource(R.drawable.whitenoisepressed);
        isPlaying++;
    }
}`

我明白了。我需要一种方法来知道我之前是否已经点击过按钮。我最初将 noiseStreaming 设置为 0,然后在按下按钮时检查它。如果它是 0,那么我将 whiteNoiseId 设置为 noiseStreaming。下次它不会是 0 并且会跳过那个位 -

public void whiteNoiseTapped(View view) {

    Log.i("White Noise", "button tapped");

    if (whiteNoisePlaying) {
        Log.i("White Noise", "already playing");
        mySound.pause(noiseStreaming);
        whiteNoisePlaying = false;
        ((ImageView) view).setImageResource(R.drawable.whitenoise);
        isPlaying--;
    } else if (isPlaying < 3) {
        Log.i("White Noise", "start playing");
        if (noiseStreaming == 0) {
            noiseStreaming = mySound.play(whiteNoiseId, (float) noiseVol, (float) noiseVol, 1, -1, 1);
        } else {
            mySound.resume(noiseStreaming);
        }
        whiteNoisePlaying = true;
        ((ImageView) view).setImageResource(R.drawable.whitenoisepressed);
        isPlaying++;
    }
}

现在可以通过点击打开和关闭来控制音量。