Dynamic playlists with Exoplayer 2
<p>I'd like to use ExoPlayer2 with playlists having possibility to dinamically change the tracks (add or remove them from playlist) and change the loop settings.</p>

<p>Since ConcatenatingMediaSource has static arrays (and not lists), I'm implementing a DynamicMediaSource, like Concatenating one but with lists instead of arrays and one mode method addSource to add one more media source to the list.</p>

<pre><code>public void addSource(MediaSource mediaSource) {
    this.mediaSources.add(mediaSource);
    duplicateFlags = buildDuplicateFlags(this.mediaSources);
    if(!mediaSources.isEmpty())
        prepareSource(mediaSources.size() -1);
    else
        prepareSource(0);
}
</code></pre>

<p>When I invoke addSource </p>

<pre><code>                MediaSource ms = buildMediaSource(mynewuri, null);
                mediaSource.addSource(ms);
</code></pre>

<p>the track is added to the arrays but it seems something is missing because I always obtain ArrayOutOfBoundsException in createPeriod method. </p>

<p>In createPeriod the method </p>

<pre><code>mediaSources.get(sourceIndex)...
</code></pre>

<p>is trying to access the index = mediaSources.size().</p>

<p>Can you help me?</p>