How to stop or destroy VideoView in Android

android, android-mediaplayer

Solution

have you intialize this in oncreate of activity-

final VideoView myVideoView = (VideoView)findViewById(R.id.videoView1);
            myVideoView.setVideoPath("/sdcard/demovideo.mp4");
            MediaController controller=new MediaController(this);
            myVideoView.setMediaController(controller);
            myVideoView.requestFocus();

Problem

In my main Activity I am playing an Video on VideoView when user click on Skip button :- ``` skip_button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub vv.stopPlayback(); vv = null; video_layout.setVisibility(View.GONE); main_layout.setVisibility(View.VISIBLE); } }); ``` Next Activity will open till now this is working fine but when coming back to previous Activity having VideoView it is taking long time to back. And this is Console Message Desplaying: ``` 04-23 16:09:29.091: I/MediaPlayer(3152): MediaPlayer 04-23 16:09:29.091: I/MediaPlayer(3152): MediaPlayer setDataSource(context, uri,headers) 04-23 16:09:29.201: I/MediaPlayer(3152): MediaPlayer setDisplay() 04-23 16:09:29.311: I/MediaPlayer(3152): MediaPlayer handleMessage what=5 04-23 16:09:29.311: I/MediaPlayer(3152): MediaPlayer handleMessage what=1 04-23 16:09:29.311: D/MediaPlayer(3152): getMetadata ```

Original source