Kaloyan Roussev
Kaloyan Roussev

Reputation: 14711

Android VideoView with MediaController - how to disable seeking while streaming

If playing a video from the device, the media player knows its exact lenght and fast-forwarding through the video by moving the thumb in the mediacontroller seekbar is seemless. If playing a streaming video from the internet, the length of the video is unknown and seeking using the thumb causes the video to stop responding.

I want to know how can I disable the thumb until the video is fully buffered? Then show it and enable fast-forwarding.

Following is my video player code:

    setContentView(R.layout.layout_fragment_video_fullscreen);
    vvVideoFullscreen = (VideoView) findViewById(R.id.vvVideoFullscreen);
    rlVideoFullscreen = (RelativeLayout) findViewById(R.id.rlVideoFullscreen);
    videoUri = Uri.parse(video.getUrl());
    vvVideoFullscreen.setVideoURI(videoUri);
    mediaController = new MediaController(this);
    mediaController.setMediaPlayer(vvVideoFullscreen);
    mediaController.setAnchorView(vvVideoFullscreen);
    vvVideoFullscreen.setMediaController(mediaController);
    vvVideoFullscreen.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

        @Override
        public void onPrepared(MediaPlayer mp) {
            progressDialog.dismiss();
            rlVideoFullscreen.setVisibility(View.VISIBLE);
            vvVideoFullscreen.start();
            mediaController.show(3000);
        }
    });

vVideoFullscreen.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

        @Override
        public void onCompletion(MediaPlayer mp) {
            finish();

        }
    });

    vvVideoFullscreen.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                if (vvVideoFullscreen.isPlaying()) {

                    vvVideoFullscreen.pause();
                    mediaController.hide();

                } else {

                    vvVideoFullscreen.start();
                    mediaController.show();

                }

            }
            return true;
        }

    }); // End of setOnTouchListener

Upvotes: 1

Views: 1975

Answers (1)

Jeroen Mols
Jeroen Mols

Reputation: 3464

Have you tried adding an onBufferingUpdateListener() to your mediaplayer? From the documentation is says:

public abstract void onBufferingUpdate (MediaPlayer mp, int percent)

Called to update status in buffering a media stream received through progressive HTTP download. The received buffering percentage indicates how much of the content has been buffered or played. For example a buffering update of 80 percent when half the content has already been played indicates that the next 30 percent of the content to play has been buffered.

So when this callback is invoked with 100%, you know your video is fully buffered.

To disable all playback controls, you can simply only call mediaController.setMediaPlayer(...) when buffering is completed.

If you want to only disable the seek thumb, I suggest to implement your own MediaController.MediaPlayerControlInterface and rout all calls to your MediaPlayer object. Seeking can then be disabled by having the canSeekForward() and canSeekBackward() methods return false and by making the seekTo(int pos) method don't do anything on your MediaPlayer.

Upvotes: 4

Related Questions