private MPD parse(InputStream in, Uri baseUrl) throws XmlPullParserException, IOException, DashParserException {
        try {
            XmlPullParser parser = Xml.newPullParser();
            parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
            parser.setInput(in, null);

            MPD mpd = new MPD();
            Period currentPeriod = null;

            int type = 0;
            while((type = parser.next()) >= 0) {
                if(type == XmlPullParser.START_TAG) {
                    String tagName = parser.getName();

                    if(tagName.equals("MPD")) {
                        mpd.isDynamic = getAttributeValue(parser, "type", "static").equals("dynamic");

                        if (mpd.isDynamic) {
                            Log.i(TAG, "dynamic MPD not supported yet, but giving it a try...");
                            // Set a dummy duration to get the stream to work for some time
                            mpd.mediaPresentationDurationUs = 1l /* h */ * 60 * 60 * 1000000;
                            mpd.timeShiftBufferDepthUs = getAttributeValueTime(parser, "timeShiftBufferDepth", "PT0S");
                            mpd.maxSegmentDurationUs = getAttributeValueTime(parser, "maxSegmentDuration", "PT0S");
                            mpd.suggestedPresentationDelayUs = getAttributeValueTime(parser, "suggestedPresentationDelay", "PT0S");
                            // TODO add support for dynamic streams with unknown duration

                            String date = getAttributeValue(parser, "availabilityStartTime");
                            try {
                                if (date.length() == 19) {
                                    date = date + "Z";
                                }
                                mpd.availabilityStartTime = ISO8601UTC.parse(date.replace("Z", "+00:00"));
                            } catch (ParseException e) {
                                Log.e(TAG, "unable to parse date: " + date);
                            }
                        } else { // type == static
                            mpd.mediaPresentationDurationUs = getAttributeValueTime(parser, "mediaPresentationDuration");
                        }
                        mpd.minBufferTimeUs = getAttributeValueTime(parser, "minBufferTime");
                    } else if(tagName.equals("Period")) {
                        currentPeriod = new Period();
                        currentPeriod.id = getAttributeValue(parser, "id");
                        currentPeriod.startUs = getAttributeValueTime(parser, "start");
                        currentPeriod.durationUs = getAttributeValueTime(parser, "duration");
                        currentPeriod.bitstreamSwitching = getAttributeValueBoolean(parser, "bitstreamSwitching");
                    } else if(tagName.equals("BaseURL")) {
                        baseUrl = extendUrl(baseUrl, parser.nextText());
                        Log.d(TAG, "base url: " + baseUrl);
                    } else if(tagName.equals("AdaptationSet")) {
                        currentPeriod.adaptationSets.add(readAdaptationSet(mpd, currentPeriod, baseUrl, parser));
                    }
                } else if(type == XmlPullParser.END_TAG) {
                    String tagName = parser.getName();
                    if(tagName.equals("MPD")) {
                        break;
                    } else if(tagName.equals("Period")) {
                        mpd.periods.add(currentPeriod);
                        currentPeriod = null;
                    }
                }
            }

            Log.d(TAG, mpd.toString());

            return mpd;
        } finally {
            in.close();
        }
    }
Parses an MPD XML file. This needs to be executed off the main thread, else a
NetworkOnMainThreadException gets thrown.
@param source the URl of an MPD XML file
@return a MPD object
@throws android.os.NetworkOnMainThreadException if executed on the main thread
MediaPlayer-DASH/src/main/java/net/protyposis/android/mediaplayer/dash/DashParser.java