Well, the code snippet intercepts all the hardware button presses... If you only want to disable during playback, and that you're not using a dedicated activity for that, then you could add an extra flag (like "boolean playing = true;", and use it in the if condition). If your application isn't too long, it might be easier to just post the code...