0

我的 MediaPlayer 有问题!!!!我播放媒体文件,暂停它,然后恢复它,当我回到活动主我的应用程序关闭时。我的代码:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
    if ((keyCode == KeyEvent.KEYCODE_BACK))
    {
            if (mediaPlayer != null) {
                mediaPlayer.release();
                mediaPlayer = null; 
            }
              seekHandler.removeCallbacks(run);
        finish();
    }
    return super.onKeyDown(keyCode, event);
}

帮我 :(

4

1 回答 1

0

实际上,您必须在onDestroy()和中释放 MediaPlayer onPause()

您不需要捕获后退按键事件:

@Override
 protected void onDestroy() {
  // TODO Auto-generated method stub
  super.onDestroy();
  if (mediaPlayer != null) {
   mediaPlayer.release();
   mediaPlayer = null; 
  }
 }

 @Override
 protected void onPause() {
  // TODO Auto-generated method stub
  super.onPause();
  if (mediaPlayer != null) {
   mediaPlayer.release();
   mediaPlayer = null; 
  }
 }
于 2013-10-11T23:50:18.830 回答