title: Play video only in active page of ViewPager
body: <p>I am displaying videos using <code>ViewPager</code>. Each page plays a different video. I would like to play the video only in the active page (other pages should be paused) like in Facebook or Instagram.   </p>
  
  <pre><code>@Override
  public void onResume() {
  
      super.onResume();
  
  
      if (player == null) {
  
          prepareplayer(bufferpos, video);
          player.setPlayWhenReady(true);
      }
  }
  
  
  @Override
  public void onPause() {
  
      super.onPause();
  
      if( player != null) {
  
          player.setPlayWhenReady(false);
      }
  
      releaseplayer();
  }
  </code></pre>