Android mediacontroller Play Pause controls not refresh properly

前端 未结 2 1993
悲哀的现实
悲哀的现实 2021-02-15 23:01

I have used MediaController in my activity its working fine but when I play video for first time then there should b pause button visible but instead there is play and when I pr

2条回答
  •  独厮守ぢ
    2021-02-15 23:27

    I've been having the same issue. I was not calling MediaController.setVideoView as you were, as I thought VideoView.setMediaController was sufficient for wiring things up. I tried adding that, then moving the call to show within onPrepared, and now it is working.

    I wish I had a better understanding; my best guess is that perhaps everything needs to be wired up properly before the media is prepared, and before calling show. In any case, here is what I have:

    mMediaController = new MediaController(VideoPlayerActivity.this, false);
    
    mVideoView.setOnPreparedListener( new MediaPlayer.OnPreparedListener() {            
        @Override
        public void onPrepared(MediaPlayer pMp) {
            mMediaController.show();
        }       
    });
    
    mVideoView.setMediaController(mMediaController);
    mMediaController.setMediaPlayer(mVideoView);
    mVideoView.setVideoPath(uri);  // may not be applicable in your case
    mVideoView.requestFocus();
    mVideoView.start();
    

提交回复
热议问题