Reputation: 641
I'm in the process of developing an Android app.
I have been able to successfully set the speaker volume using:
AudioManager audioManager = (Audiomanager)getSystemService(Context.AUDIO_SERVICE);
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, sb2value, 0);
The question is, what's the max int value that "sb2value" can be?
FYI, "sb2value" is a value from a slider. As the user slides, the audio volume is changed.
I allow that slider value to go from 0 - 100. Can 100 be used as the second argument value or is the limit lower, such as 20?
Thanks,
P.S. Most of my questions look the same because I'm new, understand that each question needs a new post, and I have a lot of problems for a simple program.
Upvotes: 13
Views: 28581
Reputation: 2085
To get the max volume you could set sb2value:
sb2value = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
Upvotes: 22
Reputation: 17189
Instead of hard coding the max value of your slider (or SeekBar if you are using that), set the Max attribute to audioManager.getStreamMaxVolume(audioManager.STREAM_MUSIC)
This will work better because different devices may have different volume limits.
As far as the actual limit, I'd imagine it isn't above 10.
Upvotes: 4
Reputation: 40218
You can use the getStreamMaxVolume(int) method to get the value you need. Hope this helps.
Upvotes: 5