How to make playback control from the volume button? When the track is playing, the button was not active. The track ended again became active. Here is the code:
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: sounds = new int[] { R.raw.muz1, R.raw.muz2, R.raw.muz3, R.raw.muz4, R.raw.muz5, R.raw.muz6, R.raw.muz6, R.raw.muz7 }; mp = MediaPlayer.create(getApplicationContext(), sounds[index]); mp.setLooping(false); mp.start(); mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { public void onCompletion(MediaPlayer mp) { mp.release(); if (index < sounds.length - 1) { index++; return; } } }); } return false; }