这是我的活动代码:
public class VideoActivity extends FragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video);
VideoView videoView = (VideoView) findViewById(R.id.activity_video_videoview);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
Uri video = Uri
.parse("http://www.ebookfrenzy.com/android_book/movie.mp4");
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();
}
}
当视频缓冲但未播放时,我想显示进度条。我该怎么办?
答案 0 :(得分:2)
设置OnPreparedListener并关闭那里的对话框:
在您的活动中声明进度对话框:
private static ProgressDialog progressDialog;
然后在onCreate方法中:
...
progressDialog = ProgressDialog.show(this, "", "Loading...", true);
videoView.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer arg0) {
progressDialog.dismiss();
videoView.start();
}
});
答案 1 :(得分:0)
检查添加的新行应该按照您的意图执行。
public class VideoActivity extends FragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video);
VideoView videoView = (VideoView) findViewById(R.id.activity_video_videoview);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
Uri video = Uri
.parse("http://www.ebookfrenzy.com/android_book/movie.mp4");
videoView.setMediaController(mediaController);
// New Line
ProgressDialog pDialog = ProgressDialog.show(this, "", "Loading Video");
videoView.setVideoURI(video);
//New Line Added
pDialog.dismiss
videoView.start();
}
}