0

I am playing a beep sound for the last 5 seconds on a Timer.

I want to regulate the volume of the audio file with the volume keys of the mobile device.

I am currently using the android.media.SoundPool class to play the two audio files used for the Timer.

I am using the following method to play the sound:

public static void playSound(int index, float speed) {
        float streamVolume = mAudioManager
                .getStreamVolume(AudioManager.STREAM_MUSIC);
        streamVolume = streamVolume
                / mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
        mSoundPool.play(mSoundPoolMap.get(index), 1, 1,
                1, 0, speed);
    }

Currently I am able to play both the audio files but want to control with the mobile device volume keys.

Kindly provide your inputs/sample code.

Thanks in advance.

smit patel
  • 129
  • 4
chiranjib
  • 5,288
  • 8
  • 53
  • 82

1 Answers1

0

Call setVolumeControlStream() on your activity, and the volume buttons will control your desired stream.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491