0

Hi When I click backbutton videoview from url dont stop. it is going to play how can I stop it when I click backbutton. I wrote within onbackpress but it doesnt work.

   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();
e.zver
  • 31
  • 5
  • I add this: killMediaPlayer(); video.stopPlayback(); then it want create a method in video.java : public static void stopPlayback() { } but it doesnt work. is there any different method? – e.zver Feb 20 '18 at 14:59
  • I edit codes but why it didnt work for me – e.zver Feb 20 '18 at 15:54

0 Answers0