在视频开始播放之前添加“请稍候加载....”

时间:2015-12-19 09:24:03

标签: android android-videoview

我的应用程序有一个按钮,单击该按钮可在dailog框中播放视频。我想在播放之前加载视频时在dailog框中添加“Please wait loading ...”文本。我尝试添加进度条但在播放视频之前看不到进度条

这是我试过的代码

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

            }
        });


}

2 个答案:

答案 0 :(得分:1)

使videodailog.XML的根布局成为相对布局并添加

在视频标记

android:layout_centerHorizontal="true"
android:layout_centerVertical="true"

进度条标签

android:layout_centerInParent="true"

答案 1 :(得分:0)

尝试使用此功能:

requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);  
setProgressBarIndeterminateVisibility(true);

隐藏它:

setProgressBarIndeterminateVisibility(false)