视频查看的进度对话框条件

时间:2018-01-19 23:01:41

标签: java android

我试图制作条件“当对话框将被解除,然后自动播放视频......”用波纹管代码,我完成了这样做,但视频视图没有自动播放...你能建议一些东西?

mycode.java

        final ProgressDialog progressDialog = new ProgressDialog(PlayVideo.this);
        // Set progressbar title
        progressDialog.setTitle("Please set the pyramid");
        // Set progressbar message
        progressDialog.setMessage("Loading...");
        // Show progressbar
        progressDialog.show();



        // Find your VideoView in your video_main.xml layout
        myVideoView = (VideoView) findViewById(R.id.video_view);

        Uri uri = getIntent().getParcelableExtra("uri");

        try {
            myVideoView.setMediaController(mediaControls);
            myVideoView.setVideoURI(uri);

        } catch (Exception e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }

        myVideoView.requestFocus();
        myVideoView.setOnPreparedListener(new OnPreparedListener() {
            // Close the progress bar and play the video
            public void onPrepared(MediaPlayer mp) {


                if(progressDialog.isShowing()) {
                    Runnable progressRunnable = new Runnable() {

                        @Override
                        public void run() {
                            progressDialog.cancel();
                        }
                    };

                    Handler pdCanceller = new Handler();
                    pdCanceller.postDelayed(progressRunnable, 3000);
                }

                if (!progressDialog.isShowing()) {
                    myVideoView.seekTo(position);
                     if (position == 0) {
                         myVideoView.start();
                     }
                     else {
                         myVideoView.pause();
                     }
                }
            }
        });

    }

1 个答案:

答案 0 :(得分:0)

一旦视频准备就绪并播放视频,这将取消您的对话

    if (progressDialog.isShowing()) {

      Runnable progressRunnable = new Runnable() {
        @Override
        public void run() {
          progressDialog.cancel();
          myVideoView.seekTo(position);
          if (position == 0) {
            myVideoView.start();
          } else {
            myVideoView.pause();
          }
        }
      };
      Handler pdCanceller = new Handler();
      pdCanceller.postDelayed(progressRunnable, 3000);
    }

我不知道你为什么要停顿。如果你能解释一下你想要实现的流程究竟是什么,那么我可以帮助你做得更好