Methods described above to change the level of an audio stream. Some devices (like Chromebooks) have volume controls but do not allow apps to use the AudioManager These methods change the volume of every app that uses the stream. The Android AudioManager mixes all audio streams of the same type together. ForĮxample, when your app replaces an existing UI.
In rare cases, you can set the volume of an audio stream programmatically.
Controlling stream volume programmatically The volume controls to STREAM_MUSIC whenever the target activity or fragment Method of the activity or fragment that controls your media. Make this call in your app’s lifecycle, typically from the onResume() SetVolumeControlStream(AudioManager.STREAM_MUSIC)
Passing in the stream type matching your attributes that you can retrieve from Unless your app is an alarm clock, you should play audio with usage
If your app isn't currently playing anything, hitting the volume keysĪdjusts the music volume (or the ringer volume before Android 9). This allows users to control the volume of each stream independently.īy default, pressing the volume control modifies the volume of the active audio Notifications, the incoming call ringer, system sounds, in-call volume, and DTMF When a user presses a volume key in a game or music app the volume shouldĬhange, even if the player is paused between songs or there’s no music for theĪndroid uses separate audio streams for playing music, alarms, Peripheral like headphones is disconnected while in use. Includes the ability to use the volume controls (either buttons or knobs on theĭevice or sliders in the UI), and to avoid suddenly playing out loud if a Users expect to be able to control the volume of an audio app.