code: @Override protected void onVisibilityChanged(View changedView, int visibility) {
      super.onVisibilityChanged(changedView, visibility);
      if (changedView != this) {
        return;
      }
  
      if (visibility == View.VISIBLE) {
        resume();
      } else {
        pause();
      }
    }
docs: Controls visibility changes to pause or resume this custom view and avoid performance
  problems.