title: Pause ExoPlayer from Adapter class when user navigates away from page playing the video
body: <p>In my Adapter class I have implemented code for the <code>ExoPlayer</code> and it works fine. The question I have is, when the user navigates away from the page with the videos, I want the <code>ExoPlayer</code> to stop automatically. Can't figure out a way to do that.</p>
  <p>If they are on the same page but just scroll down for example, the video shouldn't stop, but if they navigate away from the page playing the video, the video should pause or stop.</p>
  <p>And it's my Adapter class, so I can't call <code>onPause()</code> and <code>onResume()</code>, or is that wrong?</p>
  <p>In my other Activity I used <code>onPause()</code> and it works fine, but here I have to do it differently, right?</p>
  <p>Do I manually have to go through and write code to pause the video with each click that navigates the user away from the screen with the videos?</p>
  <pre><code> public void setVideo(String videoUrl) {
  
              try {
                  BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter.Builder(mContext).build();
                  TrackSelector trackSelector = new DefaultTrackSelector(new AdaptiveTrackSelection.Factory(bandwidthMeter));
                  mExoPlayer = ExoPlayerFactory.newSimpleInstance(mContext, trackSelector);
                  Uri videoUri = Uri.parse(videoUrl);
                  DefaultHttpDataSourceFactory dataSourceFactory = new DefaultHttpDataSourceFactory(&quot;posts&quot;);
                  ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
                  MediaSource mediaSource = new ExtractorMediaSource(videoUri, dataSourceFactory, extractorsFactory, null, null);
                  mPlayerView.setPlayer(mExoPlayer);
                  mExoPlayer.prepare(mediaSource);
                  mExoPlayer.setPlayWhenReady(false);
              } catch (Exception e) {
                  Log.e(&quot;ViewHolder&quot;, &quot;ExoPlayer error: &quot; + e.toString());
              }
          }
  </code></pre>
  <p><strong>In my EditVideoPostActivity I did it like this which works</strong></p>
  <pre><code>@Override
      protected void onPause() {
          super.onPause();
          mExoPlayer.setPlayWhenReady(false);
          mExoPlayer.getPlaybackState();
      }
  </code></pre>