如何在视频播放前显示加载器?

How to display loader before video plays?

我正在使用视频播放器并希望在它启动之前显示加载器。以下是我的代码片段。谁能帮我解决这个问题?

            showpDialog();
             String ALLOWED_URI_CHARS = "@#&=*+-_.,:!?()/~'%";
            String urlEncoded = Uri.encode(vid_path, ALLOWED_URI_CHARS);
            System.out.println(urlEncoded);
            final VideoView videoView =(VideoView) findViewById(R.id.vv);
            videoView.setVideoPath(rlEncoded);
            MediaController mediaController = new
            MediaController(this);
            mediaController.setAnchorView(videoView);
            videoView.setMediaController(mediaController);    
            videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener()  {
            @Override
           public void onPrepared(MediaPlayer mp) {
          Log.i("", "Duration = " +videoView.getDuration());
        }
    });

 hidepDialog();
 videoView.start();

然后,在 onCreate() 调用 runOnUiThread 之前,启动 dialog

progressDialog = ProgressDialog.show(this, "", "Loading...", true);

设置一个 OnPreparedListener() 以在视频准备好播放时关闭 dialog

mVideoView.setOnPreparedListener(new OnPreparedListener() {

    public void onPrepared(MediaPlayer arg0) {
        progressDialog.dismiss();
        mVideoView.start();
    }
});