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

时间:2018-02-22 05:37:04

标签: android progressdialog android-videoview

我正在使用视频播放器并希望在启动之前显示加载程序。以下是我的代码段。任何人都可以帮我解决这个问题吗?

            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();

1 个答案:

答案 0 :(得分:1)

然后,在onCreate()中,在致电runOnUiThread之前,启动dialog

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

设置OnPreparedListener(),当视频准备好播放时,dialog会关闭mVideoView.setOnPreparedListener(new OnPreparedListener() { public void onPrepared(MediaPlayer arg0) { progressDialog.dismiss(); mVideoView.start(); } });

saved