gpt4 book ai didi

android - Videoview Android 崩溃

转载 作者:行者123 更新时间:2023-12-02 14:25:02 24 4
gpt4 key购买 nike

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

@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>

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

最佳答案

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

在使用 setContentView 设置布局之前,无法引用 R.id.myvideoview

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

关于android - Videoview Android 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16882293/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com