gpt4 book ai didi

android - VideoView 变量有错误的值

转载 作者:行者123 更新时间:2023-11-30 04:18:28 27 4
gpt4 key购买 nike

有谁知道为什么我的应用程序在打印出 VideoView 中的变量时只返回错误的值?

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
VideoView video = (VideoView)findViewById(R.id.introvideo);
VideoThread IntroClip = new VideoThread();
IntroClip.execute(video);
}

private class VideoThread extends AsyncTask<VideoView, Integer, VideoView> {
@Override
protected VideoView doInBackground(VideoView... video) {
video[0].setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.intro);
return video[0];
}

protected void onPostExecute(VideoView video) {
video.start();
}
}

如果我尝试打印 video.getheight 它始终为 0,video.IsPlaying 始终为 false 等等。我必须找出视频何时停止播放。换句话说,在 onCreate 方法中是这样的:

while(video.IsPlaying())
{



}

/*Stopped playing, continue...*/

但如前所述,该值始终为 false :-/

最佳答案

找到解决方案:

VideoThread IntroClip = new VideoThread();
IntroClip.execute(video);
video.setOnCompletionListener(new MediaPlayer.OnCompletionListener(){
public void onCompletion(MediaPlayer mp) {
setContentView(R.layout.loginmenu);
}
});

引用How to start activity after VideoView end

您好!

关于android - VideoView 变量有错误的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9624147/

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