0

我目前正在使用 eclipse 开发 android 应用程序。但是,当我放置 videoView 后,应用程序崩溃了。我把 onCompletionListener 所以如果视频结束它会自动跳转到主要活动。这是我的视频视图代码:

@Override
     public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.view_video);

     playVideo();
}

public void playVideo(){
         VideoView myVideoView = (VideoView)findViewById(R.id.myvideoview);
         setContentView(myVideoView);

         Uri video = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.endingvid);
         myVideoView.setVideoURI(video);
         myVideoView.setOnCompletionListener(new OnCompletionListener() {
           public void onCompletion(MediaPlayer mp) {
            jumpMain();
           }

          });
         myVideoView.start();
}

这是xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:layout_gravity="center_vertical|center"
   android:background="@drawable/black"
   >

    <VideoView
   android:id="@+id/myvideoview"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content" />
</LinearLayout>

有人知道我的代码有什么问题吗?

4

1 回答 1

1
 VideoView myVideoView = (VideoView)findViewById(R.id.myvideoview);
 setContentView(myVideoView);

R.id.myvideoview在设置布局之前您不能参考setContentView

setContentView(R.layour.layout_with_videoview); 
VideoView myVideoView = (VideoView)findViewById(R.id.myvideoview);
于 2013-06-02T11:29:53.060 回答