android MediaPlayer 缓存监控

监控缓存开始于结束,以及其它监控信息

 @Override
 public boolean onInfo(MediaPlayer mp, int what, int extra) {
  switch (what) {
  case MediaPlayer.MEDIA_INFO_BUFFERING_START:  控制加载动画操作
   mBufferingHandler.sendEmptyMessageDelayed(MSG_BUFFERING_TIMEOUT, BUFFERING_TIMEOUT);
   mController.showLoading();
   break;
  case MediaPlayer.MEDIA_INFO_BUFFERING_END: 结束加载动画操作
   mBufferingHandler.removeMessages(MSG_BUFFERING_TIMEOUT);
   mController.showPlaying();
   break;
  case MediaPlayer.MEDIA_INFO_METADATA_UPDATE:
   break;
  case MediaPlayer.MEDIA_INFO_BAD_INTERLEAVING:
   break;
  case MediaPlayer.MEDIA_INFO_VIDEO_TRACK_LAGGING:
   break;
  case MediaPlayer.MEDIA_INFO_UNKNOWN:
   break;
  default:
   break;
  }
  return false;
 }

缓存进度监听,可以适度更新缓存进度。 

mMediaPlayer.setOnBufferingUpdateListener(new MediaPlayer.OnBufferingUpdateListener() {
   
   @Override
   public void onBufferingUpdate(MediaPlayer arg0, int arg1) {
    // TODO Auto-generated method stub
    if(arg0.isPlaying()==false){
     //弹出加载界面
     showProgressDialog(MainActivity.this,"视频加载中");
    } else {
     //hide 掉加载界面 进度条
     closeProgressDialog();
     controll_view.hiddenProgressWidget();
    }
   }
  });

你可能感兴趣的:(android MediaPlayer 缓存监控)