Skip to content Skip to sidebar Skip to footer

Mediacontrol Seekbar Issue Android

In my Android application I am facing issue with seekbar of MediaController that I am using for Videoview. I would like to know if the user seeks to a position greater than the buf

Solution 1:

mSeekBar.setOnSeekBarChangeListener(newOnSeekBarChangeListener() {

   @OverridepublicvoidonStopTrackingTouch(SeekBar arg0) {
         // you can check for the current buffer state and where the use seek using mSeekBar.getProgress() and then open up a dialog.if(condition to match buffering and seek position)
               openDialog();
   }

   @OverridepublicvoidonStartTrackingTouch(SeekBar arg0) {

   }

   @OverridepublicvoidonProgressChanged(SeekBar arg0, int progress, boolean arg2) {

   }
  });

...

publicvoidopenDialog()
{
  ...
  // check for buffer level to match your seek position// when it meets the codition,cancel the dialog.
  ...
}

Solution 2:

Couple ways of doing this.

Option 1: Just use the OnInfoListener from the media player. This will send you info when the buffering has started and stopped.

mPlayer.setOnInfoListener(OnInfo);

Then create your listener code.

// info from player sent.OnInfoListenerOnInfo=newOnInfoListener() {
        publicbooleanonInfo(MediaPlayer mp, int what, int extra) {
            Log.d(TAG,"media info what:"+what+" extra:"+extra);

            // check about buffering status.if(what==MediaPlayer.MEDIA_INFO_BUFFERING_START) {
                // note: we are assuming _progressDialog was created already
                _progressDialog.setMessage("Buffering...");
                _progressDialog.show();
            } elseif(what==MediaPlayer.MEDIA_INFO_BUFFERING_END) {
                if(_progressDialog.isShowing())
                    _progressDialog.dismiss();
            }
            returnfalse;
        }
    };

Option 2: use the OnBufferingUpdateListener to keep track of how much has been buffered.

mPlayer.setOnBufferingListener(OnBufferingUpdate);

Then create the actual listen code.

// buffering updateOnBufferingUpdateListenerOnBufferingUpdate=newOnBufferingUpdateListener() {
        @OverridepublicvoidonBufferingUpdate(MediaPlayer mp, int percent) {
                    Log.d(TAG,"BUFFERING: "+ String.valueOf(percent));
                    // store the percent value and check it in onStopTrackingTouch() // which is in your setOnSeekBarChangeListener
        }
    };

Post a Comment for "Mediacontrol Seekbar Issue Android"