如何在Android中停止或销毁VideoView

时间:2013-04-23 11:00:23

标签: android android-mediaplayer

在我的主要活动中,当用户点击“跳过”按钮时,我正在VideoView上播放视频: -

 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);    
            }
        });

下一个活动将打开,直到现在这个工作正常但是当回到之前有VideoView的Activity时,需要很长时间才能回来。

这是控制台消息显示:

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

1 个答案:

答案 0 :(得分:3)

你是否在活动的创建中初始化了这个 -

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