My app launches a Skype call. Before the call is made I want to ensure the in-call volume is set to 75% of the maximum. This is what I've tried ...
AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
int curVol = audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL);
int maxVol = audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL);
int newVol = <do some calculations>
audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL, newVol, 0);
<launch Skype call>
However, I'm finding that:
getStreamVolume always returns 5, irrespective of that the volume is actually set to on the device
setStreamVolume has no effect, no matter what value for newVol I use
Anyone know what I might be doing wrong? Also, anyone any idea of what the 'flags' argument for setStreamVolume is used for? It's not described in the API docs.
Thanks
Damian.
Related
Below code is working but not increasing the media player volume higher than the default max volume.Please help
AudioManager am =
(AudioManager) getSystemService(Context.AUDIO_SERVICE);
am.setStreamVolume(
AudioManager.STREAM_MUSIC,
am.getStreamMaxVolume(AudioManager.STREAM_MUSIC),
0);
The MediaPlayer class's setVolume() method only accepts scalars in the range [0.0, 1.0], but the classes deriving from AudioEffect can be used to amplify the MediaPlayer's audio session.
For example, LoudnessEnhancer amplifies samples by a gain specified in millibels (i.e. hundredths of decibels):
MediaPlayer player = new MediaPlayer();
player.setDataSource("https://www.example.org/song.mp3");
player.prepare();
// Increase amplitude by 20%.
double audioPct = 1.2;
int gainmB = (int) Math.round(Math.log10(audioPct) * 2000);
LoudnessEnhancer enhancer = new LoudnessEnhancer(player.getAudioSessionId());
enhancer.setTargetGain(gainmB);
It's unclear from the documentation, but it appeared to me that LoudnessEnhancer doesn't work properly with negative gains, so you may still need to use MediaPlayer's setVolume() method if you want to decrease the volume.
DynamicsProcessing provides multiple stages across multiple channels, including an input gain stage.
For increasing the volume of the device beyond the system volume u have to go in engineers mode.for that save below code.and paste it in number entering box In calling option it will directly redirect you to the engineers mode
*#*#3646633#*#*
By this you can access the system settings one thing make sure that don't use this without care it may affect your system performance.
I am making an Speaking caller name application which pause the ringtone before speaking the caller name using TextToSpeech. I am detecting the current Volume using
int musicVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
Mostly this returns 0 but sometimes 15 the correct value. The phone is in normal mode and the volume of phone is full. I need this value to correctly speak the caller name but this unpredictable behaviour is making me crazy.
What wrong am i doing? Isn't this the correct way to detect ringtone volume?
It places the example below that it functions, volume is of 0 to the 15.
public void pegarVolume(){
AudioManager AudioManager = (AudioManager) getSystemService (Context.AUDIO_SERVICE);
int musicVolume = AudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
}
I am preparing an app.My app have one options button with sound on and sound off.For that i used following code,
AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
int curVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
Unfortunately, the volume setting for that application would still reflect on the system volume setting for the stream type the application is using. What I would like to know is how to set the volume for that application only without affect the system setting.
Is it possible in android have full control over the volume of the app? Is there any method that could do that? Must I do this with code? please help me
You could use AudioTrack, a lower level sound API. It has an setStereoVolume() which operates independent of the system volume.
I am working in an android app and I need to make an optionMenu with an option to disable/enable the sounds in the app.
Is it possible in android have full control over the volume of the app?
Is there any method that could do that?
Must I do this with code?
Thanks
You can find useful information here. According to that answer, it's not possible. Just don't play the sounds.
By using AudioManager you can get current volume level and max volume level. At the time of button click/ option select you can control the volume level also. Here is the code.I hope this will help you to set volume.
AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
int curVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
To Set Volume
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC,vol_level, 0);
In order for the user to control the volume , my android application has a menu consisting of a slider that provides int values from 0 to 10 , when dragged. After I obtain a value , I must set the volume to the corresponding value chosen by the user , and well , this is the part that I don't know to implement and I 'd like to find about it.
Use the AudioManager class. Essentially the code goes as follows:
AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
audioManager.setStreamVolume(streamType, volume, flags);
The problem is that the volume of the device isn't necessarily mapped from 0 to 10 as you have in your slider. On my emulator, it's from 0 to 7. So what you need to do is getStreamMaxVolume(...) to know what your max is, and then work out your value as a fraction of that. As an example, if your user chooses volume 8 out of 10, that's equivalent to 0.8 * 7 = 5.6, which you should round to 6 out of 7.
The "stream" refers to things like ringer volume, notification volume, music volume, etc. If you want to change the volume of the ringer, you need to make sure all your commands have AudioManager.STREAM_RING as the streamType.