Search code examples
androidaudiosoundpool

Soundpool volume not changing


I have 8 different Soundpool noises, all with their own seekbar to control volume. I have logs to show that the numbers are changing from the seekbar as they should, but the volume doesn't change 90% of the time (Odd that occasionally it works).

This is the code in onCreate where the volume is set -

dryerVolumeControl.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

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

            Log.i("Dryer Volume", String.valueOf(dryerId) + " " + String.valueOf((float) dryerVol));
            mySound.setVolume(dryerId, (float) dryerVol, (float) dryerVol);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            Log.i("Dryer Volume", "On stop touching");
            mySound.setVolume(dryerId, (float) dryerVol, (float) dryerVol);
        }
    });

I added the onStop code on the off chance it would work. Id's and volume's for dryer all seem to be okay, so why would the volume not change?

If you need to see something else, please let me know. (Can I link to github so someone can check through all the code? Is that 'safe'?)


Solution

  • The dryer is started up with this code -

    dryerStreaming = mySound.play(dryerId, (float) dryerVol, (float) dryerVol, 1, -1, 1);
    

    I should then control volume with -

    mySound.setVolume(dryerStreaming, (float) dryerVol, (float) dryerVol);