Exemplo n.º 1
0
  private void initView(Context context) {
    inflate(context, R.layout.zz_video_player_controller, this);

    View rlPlayPause = findViewById(R.id.rl_play_pause);
    mIvPlayPause = (ImageView) findViewById(R.id.iv_play_pause);
    mTvCurrentTime = (TextView) findViewById(R.id.tv_current_time);
    mTvTotalTime = (TextView) findViewById(R.id.tv_total_time);

    mCsb = (CustomSeekBar) findViewById(R.id.csb);
    setProgressLayerDrawables(
        R.drawable.zz_player_shape_default_background,
        R.drawable.zz_player_shape_default_second_progress,
        R.drawable.zz_player_shape_default_progress);

    mProgressLayerDrawable = new LayerDrawable(mProgressLayers);
    mCsb.setProgressDrawable(mProgressLayerDrawable);

    View rlToggleExpandable = findViewById(R.id.rl_toggle_expandable);
    mIvToggleExpandable = (ImageView) findViewById(R.id.iv_toggle_expandable);

    rlPlayPause.setOnClickListener(this);
    rlToggleExpandable.setOnClickListener(this);
    mIvPlayPause.setOnClickListener(this);
    mCsb.setOnSeekBarChangeListener(this);
  }
Exemplo n.º 2
0
  /**
   * 更新播放进度
   *
   * @param progress 当前进度
   * @param secondProgress 缓冲进度
   * @param maxValue 最大值
   * @param isTracking 用户是否正在操作中
   */
  public void updateProgress(int progress, int secondProgress, int maxValue, boolean isTracking) {
    // 更新播放时间信息
    initFormatter(maxValue);

    // 更新进度条
    mDuration = maxValue;
    mCsb.setMax(maxValue);
    mCsb.setSecondaryProgress(secondProgress * maxValue / 100);

    if (!isTracking) {
      mCsb.setProgress(progress);
      mTvCurrentTime.setText(formatPlayTime(progress));
    }

    mTvTotalTime.setText(formatPlayTime(maxValue));
  }
Exemplo n.º 3
0
 public void setProgressLayerDrawables(@DrawableRes int resId) {
   if (mCsb != null) {
     Drawable drawable;
     if (Build.VERSION.SDK_INT >= 21) {
       drawable = getResources().getDrawable(resId, null);
     } else {
       drawable = getResources().getDrawable(resId);
     }
     mCsb.setProgressDrawable(drawable);
   }
 }
Exemplo n.º 4
0
 /** 设置进度条按钮图片 */
 public void setProgressThumbDrawable(@DrawableRes int thumbId) {
   if (thumbId > 0) {
     Drawable drawable;
     if (Build.VERSION.SDK_INT >= 21) {
       drawable = getResources().getDrawable(thumbId, null);
     } else {
       drawable = getResources().getDrawable(thumbId);
     }
     if (drawable != null && mCsb != null) {
       mCsb.setThumb(drawable);
     }
   }
 }
Exemplo n.º 5
0
 /**
  * 设置进度条样式
  *
  * @param resId 进度条progressDrawable分层资源 数组表示的进度资源分别为 background - secondaryProgress - progress
  *     若对应的数组元素值 <=0,表示该层素材保持不变; 注意:progress和secondaryProgress的shape资源需要做成clip的,否则会直接完全显示
  */
 public void setProgressLayerDrawables(@DrawableRes int... resId) {
   for (int i = 0; i < resId.length; i++) {
     if (resId[i] > 0 && i < mProgressLayers.length) {
       if (Build.VERSION.SDK_INT >= 21) {
         mProgressLayers[i] = getResources().getDrawable(resId[i], null);
       } else {
         mProgressLayers[i] = getResources().getDrawable(resId[i]);
       }
     }
   }
   mProgressLayerDrawable = new LayerDrawable(mProgressLayers);
   if (mCsb != null) {
     mCsb.setProgressDrawable(mProgressLayerDrawable);
   }
 }
Exemplo n.º 6
0
 public void updateNetworkState(boolean isAvailable) {
   mCsb.setSeekable(isAvailable);
 }