有谁知道为什么我的应用程序只在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总是假的,依此类推。 我必须找出视频何时停止播放。换句话说,在onCreate方法中有类似的东西:
while(video.IsPlaying())
{
}
/*Stopped playing, continue...*/
但值如上所述始终是假的: - /
答案 0 :(得分:1)
找到解决方案:
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
问候!