public final void setDataSource(Context context, MPD mpd, SegmentDownloader segmentDownloader, AdaptationSet adaptationSet,
                                    AdaptationLogic adaptationLogic)
            throws IOException {
        try {
            mContext = context;
            mMPD = mpd;
            mSegmentDownloader = segmentDownloader;
            mAdaptationSet = adaptationSet;
            mAdaptationLogic = adaptationLogic;
            mRepresentation = adaptationLogic.initialize(mAdaptationSet);
            mMinBufferTimeUs = Math.max(mMPD.minBufferTimeUs, 10 * 1000000L); // 10 secs min buffer time; NOTE: make sure this is above MediaPlayer's low buffering water mark
            mCurrentSegment = -1;
            mSelectedTracks = new ArrayList<>();
            mInitSegments = new ConcurrentHashMap<>(mAdaptationSet.representations.size());
            mFutureCache = new ConcurrentHashMap<>();
            mUsedCache = new SegmentLruCache(mUsedCacheSize == 0 ? 1 : mUsedCacheSize);
            mMp4Mode = mRepresentation.mimeType.equals("video/mp4") || mRepresentation.initSegment.media.endsWith(".mp4");
            mSegmentPTSOffsetUs = 0;

            /* If the extractor previously crashed and could not gracefully finish, some old temp files
             * that will never be used again might be around, so just delete all of them and avoid the
             * memory fill up with trash.
             * Only clean at startup of the first instance, else newer ones delete cache files of
             * running ones.
             */
            if (sInstanceCount++ == 0) {
                clearTempDir(mContext);
            }

            if(mSegmentProcessingThread != null) {
                mSegmentProcessingThread.quit();
            }
            if(mSegmentSwitchingThread != null) {
                mSegmentSwitchingThread.quit();
            }

            mSegmentProcessingThread = new HandlerThread("DashMediaExtractor-SegmentProcessor");
            mSegmentProcessingThread.start();
            mSegmentProcessingHandler = new Handler(mSegmentProcessingThread.getLooper(), mHandlerCallback);

            mSegmentSwitchingThread = new HandlerThread("DashMediaExtractor-SegmentSwitcher");
            mSegmentSwitchingThread.start();
            mSegmentSwitchingHandler = new Handler(mSegmentSwitchingThread.getLooper(), mHandlerCallback);
            mSegmentSwitchingBarrier = new SyncBarrier<>();

            initOnWorkerThread(getNextSegment());
        } catch (Exception e) {
            Log.e(TAG, "failed to set data source");
            throw new IOException("failed to set data source", e);
        }
    }
Encapsulates DASH data source processing. The Android API's MediaExtractor doesn't support
switching between / chaining of multiple data sources, e.g. an initialization segment and a
succeeding media data segment. This class takes care of DASH file downloads, merging init data
with media file segments, chaining multiple files and switching between them.

From outside, it looks like it is processing a single data source, similar to the Android API MediaExtractor.

Created by maguggen on 27.08.2014.
MediaPlayer-DASH/src/main/java/net/protyposis/android/mediaplayer/dash/DashMediaExtractor.java