AudioManager allows your application to control the phone’s media volume either by pressing the hardware volume buttons on the phone or programmatically.
Setting Maximum Vloume
|
1 2 3 |
AudioManager mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE); int maxVol = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, maxVol, AudioManager.FLAG_PLAY_SOUND); |
// OR
|
1 2 3 |
mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, maxVol, AudioManager.FLAG_SHOW_UI); |
// OR
|
1 2 3 4 |
mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, maxVol, AudioManager.FLAG_VIBRATE); // Etc.. |
The last parameter in setStreamVolume(), denotes flags. These control how the user is indicated of the volume change.
FLAG_PLAY_SOUND – play a system beep to indicate the volume
FLAG_SHOW_UI – displays a toast notifying the user that the media volume has been changed
FLAG_VIBRATE – vibrates your phone.
mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE,
AudioManager.FLAG_SHOW_UI);
ADJUST_LOWER Decreases the volume.
ADJUST_RAISE Increases the ringer volume.
ADJUST_SAME Maintains same Volume
Reference:
http://developer.android.com/reference/android/media/AudioManager.html
Incoming search terms:
- playsoundeffect(audiomanager flag_play_sound) android
Tagged with: Developer • Play Sound • Reference • Ringer • S Media • Stream Music • System Beep • Toast • Ui • Volume Buttons • Volume Change
Filed under: Android
Like this post? Subscribe to my RSS feed and get loads more!




Leave a Reply