title: How do I get the index of the current track being played using ExoPlayer
body: <p>I am working on an Android project that involves the use of Google's ExoPlayer.
  I have a list of video sources which I build a playlist from using the following code:</p>
  
  <pre><code>for (int i = 0; i &lt; vidList.length(); i++) {
      MediaSource source = new ExtractorMediaSource(Uri.parse(vidList.getJSONObject(i).getString("url")),
                                  buildDataSourceFactory(bandwidthMeter), extractorsFactory, mainHandler, HomeFragment.this);
                          mediaSources.add(source);
                          captions.add(vidList.getJSONObject(i).getString("caption"));
                      }
  
      mediaSource = new ConcatenatingMediaSource(mediaSources.toArray(new MediaSource[mediaSources.size()]));
  </code></pre>
  
  <p>I then call</p>
  
  <pre><code>exoplayer.prepare(mediasource, false, false)
  </code></pre>
  
  <p>and the videos play in succession fine. I would like to display the caption of the currently playing video in a textView and so I have a separate list that holds the "caption" values for each video.</p>
  
  <p>From scouring through the code I see that I can get the currently playing video in the playlist like this;</p>
  
  <pre><code>exoPlayer.getCurrentPeriodIndex()
  </code></pre>
  
  <p>Which seems to work and returns the index except for one problem. It returns the value of 0 twice as playback starts. That is video at index 0 returns period 0 as well as video at index 1. This only occurs at indexes 0 and 1 and thereafter everything else looks fine except that the getCurrentPeriodIndex() will return theAccurateIndex - 1.</p>
  
  <p>I see this also happening in the demo Exoplayer application.
  Is there a better way to determine what track is currently playing in the playlist?</p>
  
  <p>Thanks.</p>