如何在视频加载前在dailog框中显示进度条

时间:2015-12-19 07:29:48

标签: android dialog progress-bar android-videoview

我的应用程序在按钮单击时在dailog框中播放视频。我希望在dailog框中播放视频之前显示进度条。但是当单击按钮时,进度条在dailog框中不可见,但视频会播放。

我的按钮点击方法

public void plyvido(){
    final Dialog dialog = new Dialog(MainActivity.this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.videodialog);
    dialog.show();
    MediaController mediacontroller = new MediaController(
        MainActivity.this);
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
        LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    lp.copyFrom(dialog.getWindow().getAttributes());

    dialog.getWindow().setAttributes(lp);

    videoview = (VideoView) dialog.findViewById(R.id.videodialogVideoView);
    progressBar = (ProgressBar) dialog.findViewById(R.id.progressbar);
    mediacontroller.setAnchorView(videoview);
    Uri uri = Uri.parse(VideoURL);
    videoview.setZOrderOnTop(true);
    videoview.setVideoURI(uri);
    videoview.setMediaController(mediacontroller);
    progressBar.setVisibility(View.VISIBLE);
    videoview.start();



    //progressBar.setVisibility(View.VISIBLE);
    videoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                // TODO Auto-generated method stub
                mp.start();
                mp.setOnVideoSizeChangedListener(new MediaPlayer.OnVideoSizeChangedListener() {
                        @Override
                        public void onVideoSizeChanged(MediaPlayer mp, int arg1,
                                                       int arg2) {
                            // TODO Auto-generated method stub
                            progressBar.setVisibility(View.GONE);
                            mp.start();
                        }
                    });

            }
        });


}

0 个答案:

没有答案