private SegmentTemplate readSegmentTemplate(XmlPullParser parser, Uri baseUrl, SegmentTemplate parent)
            throws IOException, XmlPullParserException, DashParserException {
        SegmentTemplate st = new SegmentTemplate();

        // Read properties from template or carry them over from a parent

        st.timescale = getAttributeValueLong(parser, "timescale", parent != null ? parent.timescale : 1);
        long presentationTimeOffset = getAttributeValueLong(parser, "presentationTimeOffsetUs", parent != null ? parent.presentationTimeOffsetUs : 0);
        st.presentationTimeOffsetUs = calculateUs(presentationTimeOffset, st.timescale);
        st.duration = getAttributeValueLong(parser, "duration", parent != null ? parent.duration : 0);
        st.startNumber = getAttributeValueInt(parser, "startNumber", parent != null ? parent.startNumber : 1);

        String initialization = getAttributeValue(parser, "initialization");
        if(initialization != null) {
            st.init = extendUrl(baseUrl, initialization).toString();
        } else if(parent != null) {
            st.init = parent.init;
        }

        String media = getAttributeValue(parser, "media");
        if(media != null) {
            st.media = extendUrl(baseUrl, media).toString();
        } else if(parent != null) {
            st.media = parent.media;
        }

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

                if(tagName.equals("S")) {
                    SegmentTemplate.SegmentTimelineEntry e = new SegmentTemplate.SegmentTimelineEntry();

                    long defaultTime = 0;
                    if(!st.timeline.isEmpty()) {
                        SegmentTemplate.SegmentTimelineEntry previous = st.timeline.get(st.timeline.size() - 1);
                        defaultTime = previous.t + previous.calculateDuration();
                    }

                    e.t = getAttributeValueLong(parser, "t", defaultTime);
                    e.d = getAttributeValueLong(parser, "d");
                    e.r = getAttributeValueInt(parser, "r");

                    st.timeline.add(e);
                } else if(tagName.equals("RepresentationIndex")) {
                    throw new DashParserException("RepresentationIndex is not supported yet");
                }
            } else if(type == XmlPullParser.END_TAG) {
                String tagName = parser.getName();
                if(tagName.equals("SegmentTemplate")) {
                    return st;
                }
            }
        }

        throw new DashParserException("invalid state");
    }
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