My Android app plays audio, even when other music is being played by device or some other app.
I want to take user input from SeekBar & set my app’s volume in background, as percentage to the current device music volume.I want to set my Android app’s volume as ‘n%’ of device volume at any time, ‘n’ being the value of SeekBar in the app.
I tried doing this:
volumeSeekbar.setMax(100);
@Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
{
progress = (progress * (myAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC)))/100;
myAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, progress, 0);
}
But above code will change overall device volume. In my case, I want device music to be uninterrupted & retain its volume.
Let’s say if device music is being played at volume 80, and user sets app’s Seekbar to 50, then app audio should be played at volume 50%(80) = 40. In this case both the audios will be played, device volume being retained at 80 & app volume as 50% of 80. If device volume or SeekBar value changes at any time, app volume should also change.
How to achieve this?