两个音池音量控制

Two soundpool volume controls

我正在制作一个白噪声应用程序,我想独立控制每个声音的音量。这可能吗?

这是我现在的 onCreate。

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mySound = new SoundPool(3, AudioManager.STREAM_MUSIC, 0);
    whiteNoiseId = mySound.load(this, R.raw.whitenoise, 1);
    rainId = mySound.load(this, R.raw.rain, 1);


    audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    int curVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);

    SeekBar noiseVolumeControl = (SeekBar) findViewById(R.id.noiseSeekBar);
    noiseVolumeControl.setMax(maxVolume);
    noiseVolumeControl.setProgress(curVolume);
    SeekBar rainVolumeControl = (SeekBar) findViewById(R.id.rainSeekBar);
    rainVolumeControl.setMax(maxVolume);
    rainVolumeControl.setProgress(curVolume);

    noiseVolumeControl.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, progress, 0);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });

    rainVolumeControl.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, progress, 0);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });

}

这只控制主音量,我希望能够降低一个并提高另一个。

谢谢!

应该使用 SoundPool.setVolume(int id,float leftVol,float rightVol); 方法。我没试过,不过我猜应该是:

mySound.setVolume(whiteNoiseId,0.2,0.2);

mySoundPool.setVolume(rainId,0.8,0.8);