Using the Activity’s setVolumeControlStream method—typically within its onCreate method—
allows you to specify which audio stream should be controlled by the volume keys while the current
Activity is active:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.audioplayer);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
}
You can specify any of the available audio streams, but when using the Media Player, you should
specify the STREAM_MUSIC stream to make it the focus of the volume keys.