Maison > Questions et réponses > le corps du texte
我用VideoView播放视频,因为是加载网络视频么,等一会才能加载出来,我想加个加载框ProgressBar来提醒用户等待,我利用Handle每隔半秒就检测视频是否isPlaying中,但是没效果,网上也有用setOnInfoListener这个接口来控制,但是我试过了 没反应。有哪位大神做过类似的程序吗?可否告知一下?谢谢
这是我的代码:
public class PlayVideoActivity extends CommonActivity
{
@Bind(R.id.playVideo_vv)
VideoView playVideoVv;
@Bind(R.id.pb)
ProgressBar pb;
private String videoPath;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.playvideoactivity);
ButterKnife.bind(this);
initView();
}
Handler handler=new Handler();
Runnable runnable=new Runnable()
{
@Override
public void run()
{
if (playVideoVv.isPlaying())
{
pb.setVisibility(View.GONE);
}else{
pb.setVisibility(View.VISIBLE);
}
handler.postDelayed(runnable,500);
}
};
private void initView()
{
pb.setVisibility(View.VISIBLE);
videoPath=getIntent().getStringExtra("videoPath");
playVideoVv.setVideoPath(videoPath);
MediaController mediaController = new MediaController(this,false);
// 设置VideView与MediaController建立关联
playVideoVv.setMediaController(mediaController);
// 设置MediaController与VideView建立关联
mediaController.setMediaPlayer(playVideoVv);
// 让VideoView获取焦点
playVideoVv.requestFocus();
playVideoVv.start();
}
}