Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android SDK. audioManager. setStreamVolume max int value

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.

like image 990
Marc Brown Avatar asked Feb 11 '12 17:02

Marc Brown


People also ask

Which of the following method returns the current volume index for a particular stream?

getStreamVolume(int streamtype) – This method returns the current volume index for a certain stream of the device. getStreamMaxVolume(int streamtype) – This method returns the maximum volume index for a certain stream of the device.

How do I use Audio Manager?

You can easily control your ringer volume and ringer profile i-e:(silent,vibrate,loud e.t.c) in android. Android provides AudioManager class that provides access to these controls. In order to use AndroidManager class, you have to first create an object of AudioManager class by calling the getSystemService() method.


2 Answers

To get the max volume you could set sb2value:

sb2value = audioManager.getStreamMaxVolume(audioManager.STREAM_MUSIC);
like image 174
Neil Hoff Avatar answered Nov 15 '22 12:11

Neil Hoff


You can use the getStreamMaxVolume(int) method to get the value you need. Hope this helps.

like image 45
Egor Avatar answered Nov 15 '22 14:11

Egor