我目前正在使用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>
任何人都知道我的代码有什么问题吗?
答案 0 :(得分: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);