点击后退按钮后如何停止视频观看?

时间:2018-02-20 14:39:51

标签: android android-videoview

嗨当我点击后退按钮时,来自url的视频不要停止。它会发挥作用当我点击后退按钮时如何阻止它。我在onbackpress中写道,但它不起作用。

   private void playVideo(String mMp3) {
    try {
        VideoView video = (VideoView) findViewById(R.id.videoview);
        MediaController mediacontroller = new MediaController(
                DetailActivity.this);
        mediacontroller.setAnchorView(video);
        Uri uri = Uri.parse(mMp3);
        video.setMediaController(mediacontroller);
        video.setVideoURI(uri);
        video.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

@Override
public void onBackPressed() {
    killMediaPlayer();if(null!=video){
        video.stopPlayback();
    }
    //stopVideo();
    Intent but3 = new Intent(DetailActivity.this, MainActivity.class);
    DetailActivity.this.startActivity(but3);
    DetailActivity.this.finish();

0 个答案:

没有答案