Android: Control media volume instead of ringer volume with volume buttons

It makes sense that Android, by default, leaves the volume controls to change the ringer volume. Not all apps play sounds or videos so it'll be annoying to press home every time you want to change the volume.
However, if your app plays sounds at irregular intervals then you'd notice that the volume can only be controlled while they are playing.
So how can you change the volume of the sound effects while you're in the app? Amazingly, it involves no overriding of event listeners for buttons or implementing of listeners.
During your Activity.onCreate() call, simply add this magical one liner:
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
That's it! Now the volume buttons will behave.
I could not find that in the documentation for the life of me, but it was scattered across a few StackOverflow questions.
kim jong beiber
This magical one liner will leave you feeling awesome, just like Kim Jong Il Beiber.
[ Source ]
 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog