Android mediacontroller Play Pause controls not refresh properly
Asked Answered
C

2

8

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 press that button then the video is paused correctly and state remains the same and after that its working properly. And same thing happens when Video Completed. Is this a bug or I am doing any thing wrong?

videoView.setOnPreparedListener(new OnPreparedListener() {
    @Override
    public void onPrepared(MediaPlayer mp) {
            mediaController = new MediaController(VideoPlayerActivity.this){
        public void hide(){
        }
        public void show(){
            if(isPlayingAd){
                super.hide();
            }else{
                super.show();
            }
        }
    };
    videoView.setMediaController(mediaController);
    mediaController.setMediaPlayer(videoView);
    mediaController.show();
    }
});
Chromaticity answered 27/7, 2012 at 6:39 Comment(0)
M
6

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();
Micheal answered 4/8, 2012 at 0:1 Comment(1)
I had to call mVideoView.start() before mMediaController.show(). Both calls are in onPrepared(MediaPlayer pMp) in my case. That was the only way to get it working on a Samsung device with Android 4.2.2Mckinney
T
0

As Oneworld mentioned on the other answer, I had same issue with old Samsung devices. Even though MediaController wired with VideoView properly, play button loses its sync until pause and play again with MediaController.

This thing seems only happens on old Samsung devices(KitKat and below i guess).

The only solution I found was play video programmically by videoview.start() before showing controller by mc.show().

Terryterrye answered 30/6, 2016 at 14:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.