Android VideoView(PhoneWindowLeaked Error)

时间:2014-05-26 13:44:01

标签: android android-videoview

我的VideoView中有一个Activity,下面有一些TextView和EditText。 VideoView中的视频是从服务器加载的。我必须始终显示VideoView的Media Controls。我已经覆盖了MediaController中的hide()。在OnPrepared() start()之后,我将VideoView设置为show()。它显示了我想要的控件。我已经编写了代码来完成按下设备后退按钮时的活动。现在我的问题是,当我按手机的后退按钮时,活动无法完成。当我转到其他一些活动时,它会在控制台中显示PhoneWindowLeaked异常。我对此毫无头绪。我在谷歌甚至在这个网站上找不到任何东西。请帮我解决这个问题。

示例代码段如下:

VideoView mVideoView=(VideoView)findViewById(R.id.videoView);
mVideoView.setOnTouchListener(new OnTouchListener() {
   @Override
   public boolean onTouch(View v, MotionEvent event) {
        return true;
   }
});
mVideoView.setOnCompletionListener(new OnCompletionListener() {
   @Override
   public void onCompletion(MediaPlayer mp) {
        mVideoView.setVisibility(View.INVISIBLE);
   }
});
mVideoView.setOnErrorListener(new OnErrorListener() {
   @Override
   public boolean onError(MediaPlayer mp, int what, int extra) {
      return true;
   }
});
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
   if (keyCode == KeyEvent.KEYCODE_BACK||keyCode == KeyEvent.KEYCODE_HOME) {
      if(mVideoView.isPlaying()){
         mVideoView.stopPlayback();
         mVideoView.suspend();
      }
      finish();
      return false;
   }
   return super.onKeyDown(keyCode, event);
}
mediaController = new MediaController(SampleActivity.this, true){
   public void hide() {};
};
mediaController.setMediaPlayer(mVideoView);
mediaController.setAnchorView(mVideoView);
mediaController.requestFocus();
mVideoView.setMediaController(mediaController);
Uri video = Uri.parse(getResources().getString(R.string.img_path) + csPath);
mVideoView.setVideoURI(video);
mVideoView.setOnPreparedListener(new OnPreparedListener() {
   @Override
   public void onPrepared(MediaPlayer mp) {
      mVideoView.start();
      mediaController.show(900000000);
   }
});
@Override
protected void onPause() {
   mediaController.hide();
   mVideoView.stopPlayback();
   mVideoView.suspend();
   super.onPause();
}
@Override
protected void onStop() {
   super.onStop();
   mediaController.hide();
}

由于

0 个答案:

没有答案