So I have 8 images, each starts a loop of 8 different sounds. I have a seekbar under each image to control the volume for that sound.
The seekbar works fine the first time the sounds starts, but when stopped and started again, the seekbar no longer controls the volume. What am I doing wrong? `noiseVolumeControl.setOnSeekBarChangeListener(new 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++;
}
}`
I figured it out. I needed a way of knowing if I had already tapped the button before or not. I set noiseStreaming to 0 initially and then checked it when the button was pressed. If it was 0 then I set the whiteNoiseId into noiseStreaming. Next time it wouldn't be 0 and would skip that bit -
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++;
}
}
The volume can now be controlled through clicks on and off.