@Override
    public int readSampleData(ByteBuffer byteBuf, int offset) {
        int size = super.readSampleData(byteBuf, offset);
        if(size == -1) {
            /* EOS of current segment reached. Check for and read from successive segment if
             * existing, else return the EOS flag. */
            try {
                if (switchToNextSegment()) {
                    /* If the representation switches during this read call, we cannot continue reading
                     * data from the next segment, because the video codec needs to reinitialize before.
                     * Else, some data is first fed into the decoder and then it is reinitialized, which
                     * results in skipped (sync) frames and artifacts.
                     * By returning 0, the decoder has time to check if the representation has changed,
                     * reconfigure itself and then issue another read. */
                    if (mRepresentationSwitched) {
                        return 0;
                    } else {
                        return super.readSampleData(byteBuf, offset);
                    }
                }
            } catch (IOException e) {
                Log.e(TAG, "segment switching failed", e);
            }
        }
        return size;
    }
Sets the size of the segment cache.
On Android before API 21, the size must be set before setting the data source (which is when the
cache is created), else an exception will be thrown. From Android 21 Lollipop onward,
the cache can be dynamically resized at any time.

Segments that are larger than the cache size will not be cached. Setting a very small cache
size or zero cache size effectively disables caching.

@param sizeInBytes the size of the segment cache in bytes
@throws IllegalStateException on Android before API 21 if the data source has already been set
MediaPlayer-DASH/src/main/java/net/protyposis/android/mediaplayer/dash/DashMediaExtractor.java