1

I tried to play video in dialog activity, where MediaController is displayed at the bottom of the dialog activity screen properly and when the video starts playing for the first time progress bar moves and time seconds count, but the play button doesn't change to pause button(only changes when it is clicked) and progress bar stuck in the middle of its way (doesn't reach to the finish point and time seconds stop counting).
Note: Same is the case with custom alert dialog.

How can I overcome these problems with the media controller controls? Thanks for your time and help. Here is the code of alert dialog activity.

public class DialogActivity extends Activity {

    VideoView videoView;
    MediaController mediaController;
    FrameLayout videoViewWrapper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dialog_acitivty);

        Uri videoUri = getIntent().getParcelableExtra("VideoURI");

        videoView = findViewById(R.id.videoView);
        videoView.setVideoURI(videoUri);
        videoView.start();

        videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {

                mediaController = new MediaController(DialogActivity.this);
                videoView.setMediaController(mediaController);
                mediaController.setAnchorView(videoView);
                mediaController.show();

                ((ViewGroup) mediaController.getParent()).removeView(mediaController);

                ((FrameLayout) findViewById(R.id.videoViewWrapper))
                        .addView(mediaController);
                mediaController.setVisibility(View.VISIBLE);
                //mediaController.show();
            }
        });
    }
}
shehzy
  • 2,215
  • 3
  • 25
  • 45

0 Answers0