Android: How to Stop Media Player play when Home button is pressed


Here is the solution, tested and verified

@Override
protected void onPause() {
        if (mediaPlayer != null) {
            mediaPlayer.stop();
            mediaPlayer.release();
            mediaPlayer = null;
                        }
}