0

I develop a music player application.

In my application media player played a group of songs sequencely. I used a back button to stop the mediaplayer, but if the back button is used the mediaplayer does not stoped.
How to stop the mediaplayer, when I pressed a back button?

Here my code:

Intent i = new Intent(player.this, main.class);
                    mp.stop();
                    mp.release();
                    array1.clear();                     
                    startActivity(i);
4

1 回答 1

1
   public boolean onKeyDown(int keyCode, KeyEvent event) 
    {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) 
        {
            if(mp != null)
            {
                mp.stop();
                mp.release();
                return true;
            }
        }
        return super.onKeyDown(keyCode, event);
    }

Please write above code in your activity.

于 2012-04-16T13:21:09.660 回答