Mediacontrol seekbar issue android

北战南征 提交于 2019-12-11 18:55:17

问题


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 buffered position,I need to show a dialog and then dismiss the dialogue on seek completed.
Please let me know if I can have this solved.


回答1:


mSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

   @Override
   public void onStopTrackingTouch(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();
   }

   @Override
   public void onStartTrackingTouch(SeekBar arg0) {

   }

   @Override
   public void onProgressChanged(SeekBar arg0, int progress, boolean arg2) {

   }
  });

...

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



回答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.
OnInfoListener OnInfo = 
    new OnInfoListener() {
        public boolean onInfo(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();
            } else if(what==MediaPlayer.MEDIA_INFO_BUFFERING_END) {
                if(_progressDialog.isShowing())
                    _progressDialog.dismiss();
            }
            return false;
        }
    };

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

mPlayer.setOnBufferingListener(OnBufferingUpdate);

Then create the actual listen code.

// buffering update
OnBufferingUpdateListener OnBufferingUpdate =
    new OnBufferingUpdateListener() {
        @Override
        public void onBufferingUpdate(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
        }
    };


来源:https://stackoverflow.com/questions/8253129/mediacontrol-seekbar-issue-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!