Reputation: 2552
I'm developing a game and when the game is playing the volume control is not working. Can anyone give me the solution?
It is in AndEngine
Upvotes: 2
Views: 3485
Reputation: 697
I override onKeyDown and not properly handling volume keys, my solution is this:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
boolean ret = super.onKeyDown(keyCode, event);
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP
|| keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
|| keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) {
return ret;
}
return handleKeyDown(keyCode, event);
}
Upvotes: 0
Reputation: 2552
I found the solution. Where the keycodes are handled return false and volume will start working. I was handling back button and returning true in all cases there. So what I did was that I returned true only when keypressed is back else return false and my problem solved.
Upvotes: 8
Reputation: 1169
There are four kind of sound setting in android 1)Alarm 2)Music 3)Ring Tone 4)Notification First Create object of AudioManager amanager; IF you want to set Volume use this code
For Notification
AudioManager amanager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
amanager.setStreamVolume(AudioManager.STREAM_NOTIFICATION, AudioManager.FLAG_SHOW_UI + AudioManager.FLAG_PLAY_SOUND);
For Alerm
amanager.setStreamVolume(AudioManager.STREAM_ALARM,AudioManager.FLAG_SHOW_UI + AudioManager.FLAG_PLAY_SOUND);
For Music
amanager.setStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.FLAG_SHOW_UI + AudioManager.FLAG_PLAY_SOUND);
For Ring Tone
amanager.setStreamVolume(AudioManager.STREAM_RING,AudioManager.FLAG_SHOW_UI + AudioManager.FLAG_PLAY_SOUND);
Upvotes: 2