Search in sources :

Example 61 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser in project ExoPlayer by google.

the class DashManifestParser method parseMediaPresentationDescription.

protected DashManifest parseMediaPresentationDescription(XmlPullParser xpp, String baseUrl) throws XmlPullParserException, IOException {
    long availabilityStartTime = parseDateTime(xpp, "availabilityStartTime", C.TIME_UNSET);
    long durationMs = parseDuration(xpp, "mediaPresentationDuration", C.TIME_UNSET);
    long minBufferTimeMs = parseDuration(xpp, "minBufferTime", C.TIME_UNSET);
    String typeString = xpp.getAttributeValue(null, "type");
    boolean dynamic = typeString != null && typeString.equals("dynamic");
    long minUpdateTimeMs = dynamic ? parseDuration(xpp, "minimumUpdatePeriod", C.TIME_UNSET) : C.TIME_UNSET;
    long timeShiftBufferDepthMs = dynamic ? parseDuration(xpp, "timeShiftBufferDepth", C.TIME_UNSET) : C.TIME_UNSET;
    long suggestedPresentationDelayMs = dynamic ? parseDuration(xpp, "suggestedPresentationDelay", C.TIME_UNSET) : C.TIME_UNSET;
    UtcTimingElement utcTiming = null;
    Uri location = null;
    List<Period> periods = new ArrayList<>();
    long nextPeriodStartMs = dynamic ? C.TIME_UNSET : 0;
    boolean seenEarlyAccessPeriod = false;
    boolean seenFirstBaseUrl = false;
    do {
        xpp.next();
        if (XmlPullParserUtil.isStartTag(xpp, "BaseURL")) {
            if (!seenFirstBaseUrl) {
                baseUrl = parseBaseUrl(xpp, baseUrl);
                seenFirstBaseUrl = true;
            }
        } else if (XmlPullParserUtil.isStartTag(xpp, "UTCTiming")) {
            utcTiming = parseUtcTiming(xpp);
        } else if (XmlPullParserUtil.isStartTag(xpp, "Location")) {
            location = Uri.parse(xpp.nextText());
        } else if (XmlPullParserUtil.isStartTag(xpp, "Period") && !seenEarlyAccessPeriod) {
            Pair<Period, Long> periodWithDurationMs = parsePeriod(xpp, baseUrl, nextPeriodStartMs);
            Period period = periodWithDurationMs.first;
            if (period.startMs == C.TIME_UNSET) {
                if (dynamic) {
                    // This is an early access period. Ignore it. All subsequent periods must also be
                    // early access.
                    seenEarlyAccessPeriod = true;
                } else {
                    throw new ParserException("Unable to determine start of period " + periods.size());
                }
            } else {
                long periodDurationMs = periodWithDurationMs.second;
                nextPeriodStartMs = periodDurationMs == C.TIME_UNSET ? C.TIME_UNSET : (period.startMs + periodDurationMs);
                periods.add(period);
            }
        }
    } while (!XmlPullParserUtil.isEndTag(xpp, "MPD"));
    if (durationMs == C.TIME_UNSET) {
        if (nextPeriodStartMs != C.TIME_UNSET) {
            // If we know the end time of the final period, we can use it as the duration.
            durationMs = nextPeriodStartMs;
        } else if (!dynamic) {
            throw new ParserException("Unable to determine duration of static manifest.");
        }
    }
    if (periods.isEmpty()) {
        throw new ParserException("No periods found.");
    }
    return buildMediaPresentationDescription(availabilityStartTime, durationMs, minBufferTimeMs, dynamic, minUpdateTimeMs, timeShiftBufferDepthMs, suggestedPresentationDelayMs, utcTiming, location, periods);
}
Also used : ParserException(com.google.android.exoplayer2.ParserException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) ArrayList(java.util.ArrayList) Uri(android.net.Uri) Pair(android.util.Pair)

Example 62 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser in project ExoPlayer by google.

the class SsManifestParser method parse.

@Override
public SsManifest parse(Uri uri, InputStream inputStream) throws IOException {
    try {
        XmlPullParser xmlParser = xmlParserFactory.newPullParser();
        xmlParser.setInput(inputStream, null);
        SmoothStreamingMediaParser smoothStreamingMediaParser = new SmoothStreamingMediaParser(null, uri.toString());
        return (SsManifest) smoothStreamingMediaParser.parse(xmlParser);
    } catch (XmlPullParserException e) {
        throw new ParserException(e);
    }
}
Also used : ParserException(com.google.android.exoplayer2.ParserException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 63 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser in project ExoPlayer by google.

the class TtmlDecoder method decode.

@Override
protected TtmlSubtitle decode(byte[] bytes, int length) throws SubtitleDecoderException {
    try {
        XmlPullParser xmlParser = xmlParserFactory.newPullParser();
        Map<String, TtmlStyle> globalStyles = new HashMap<>();
        Map<String, TtmlRegion> regionMap = new HashMap<>();
        regionMap.put(TtmlNode.ANONYMOUS_REGION_ID, new TtmlRegion());
        ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes, 0, length);
        xmlParser.setInput(inputStream, null);
        TtmlSubtitle ttmlSubtitle = null;
        LinkedList<TtmlNode> nodeStack = new LinkedList<>();
        int unsupportedNodeDepth = 0;
        int eventType = xmlParser.getEventType();
        FrameAndTickRate frameAndTickRate = DEFAULT_FRAME_AND_TICK_RATE;
        while (eventType != XmlPullParser.END_DOCUMENT) {
            TtmlNode parent = nodeStack.peekLast();
            if (unsupportedNodeDepth == 0) {
                String name = xmlParser.getName();
                if (eventType == XmlPullParser.START_TAG) {
                    if (TtmlNode.TAG_TT.equals(name)) {
                        frameAndTickRate = parseFrameAndTickRates(xmlParser);
                    }
                    if (!isSupportedTag(name)) {
                        Log.i(TAG, "Ignoring unsupported tag: " + xmlParser.getName());
                        unsupportedNodeDepth++;
                    } else if (TtmlNode.TAG_HEAD.equals(name)) {
                        parseHeader(xmlParser, globalStyles, regionMap);
                    } else {
                        try {
                            TtmlNode node = parseNode(xmlParser, parent, regionMap, frameAndTickRate);
                            nodeStack.addLast(node);
                            if (parent != null) {
                                parent.addChild(node);
                            }
                        } catch (SubtitleDecoderException e) {
                            Log.w(TAG, "Suppressing parser error", e);
                            // Treat the node (and by extension, all of its children) as unsupported.
                            unsupportedNodeDepth++;
                        }
                    }
                } else if (eventType == XmlPullParser.TEXT) {
                    parent.addChild(TtmlNode.buildTextNode(xmlParser.getText()));
                } else if (eventType == XmlPullParser.END_TAG) {
                    if (xmlParser.getName().equals(TtmlNode.TAG_TT)) {
                        ttmlSubtitle = new TtmlSubtitle(nodeStack.getLast(), globalStyles, regionMap);
                    }
                    nodeStack.removeLast();
                }
            } else {
                if (eventType == XmlPullParser.START_TAG) {
                    unsupportedNodeDepth++;
                } else if (eventType == XmlPullParser.END_TAG) {
                    unsupportedNodeDepth--;
                }
            }
            xmlParser.next();
            eventType = xmlParser.getEventType();
        }
        return ttmlSubtitle;
    } catch (XmlPullParserException xppe) {
        throw new SubtitleDecoderException("Unable to decode source", xppe);
    } catch (IOException e) {
        throw new IllegalStateException("Unexpected error when reading input.", e);
    }
}
Also used : HashMap(java.util.HashMap) XmlPullParser(org.xmlpull.v1.XmlPullParser) IOException(java.io.IOException) LinkedList(java.util.LinkedList) SubtitleDecoderException(com.google.android.exoplayer2.text.SubtitleDecoderException) ByteArrayInputStream(java.io.ByteArrayInputStream) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 64 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser in project XobotOS by xamarin.

the class SearchableInfo method getActivityMetaData.

/**
     * Get the metadata for a given activity
     * 
     * @param context runtime context
     * @param xml XML parser for reading attributes
     * @param cName The component name of the searchable activity
     * 
     * @result A completely constructed SearchableInfo, or null if insufficient XML data for it
     */
private static SearchableInfo getActivityMetaData(Context context, XmlPullParser xml, final ComponentName cName) {
    SearchableInfo result = null;
    Context activityContext = createActivityContext(context, cName);
    if (activityContext == null)
        return null;
    // forward through the file until it's reading the tag of interest.
    try {
        int tagType = xml.next();
        while (tagType != XmlPullParser.END_DOCUMENT) {
            if (tagType == XmlPullParser.START_TAG) {
                if (xml.getName().equals(MD_XML_ELEMENT_SEARCHABLE)) {
                    AttributeSet attr = Xml.asAttributeSet(xml);
                    if (attr != null) {
                        try {
                            result = new SearchableInfo(activityContext, attr, cName);
                        } catch (IllegalArgumentException ex) {
                            Log.w(LOG_TAG, "Invalid searchable metadata for " + cName.flattenToShortString() + ": " + ex.getMessage());
                            return null;
                        }
                    }
                } else if (xml.getName().equals(MD_XML_ELEMENT_SEARCHABLE_ACTION_KEY)) {
                    if (result == null) {
                        // Can't process an embedded element if we haven't seen the enclosing
                        return null;
                    }
                    AttributeSet attr = Xml.asAttributeSet(xml);
                    if (attr != null) {
                        try {
                            result.addActionKey(new ActionKeyInfo(activityContext, attr));
                        } catch (IllegalArgumentException ex) {
                            Log.w(LOG_TAG, "Invalid action key for " + cName.flattenToShortString() + ": " + ex.getMessage());
                            return null;
                        }
                    }
                }
            }
            tagType = xml.next();
        }
    } catch (XmlPullParserException e) {
        Log.w(LOG_TAG, "Reading searchable metadata for " + cName.flattenToShortString(), e);
        return null;
    } catch (IOException e) {
        Log.w(LOG_TAG, "Reading searchable metadata for " + cName.flattenToShortString(), e);
        return null;
    }
    return result;
}
Also used : Context(android.content.Context) AttributeSet(android.util.AttributeSet) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException)

Example 65 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser in project XobotOS by xamarin.

the class InsetDrawable method inflate.

@Override
public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs) throws XmlPullParserException, IOException {
    int type;
    TypedArray a = r.obtainAttributes(attrs, com.android.internal.R.styleable.InsetDrawable);
    super.inflateWithAttributes(r, parser, a, com.android.internal.R.styleable.InsetDrawable_visible);
    int drawableRes = a.getResourceId(com.android.internal.R.styleable.InsetDrawable_drawable, 0);
    int inLeft = a.getDimensionPixelOffset(com.android.internal.R.styleable.InsetDrawable_insetLeft, 0);
    int inTop = a.getDimensionPixelOffset(com.android.internal.R.styleable.InsetDrawable_insetTop, 0);
    int inRight = a.getDimensionPixelOffset(com.android.internal.R.styleable.InsetDrawable_insetRight, 0);
    int inBottom = a.getDimensionPixelOffset(com.android.internal.R.styleable.InsetDrawable_insetBottom, 0);
    a.recycle();
    Drawable dr;
    if (drawableRes != 0) {
        dr = r.getDrawable(drawableRes);
    } else {
        while ((type = parser.next()) == XmlPullParser.TEXT) {
        }
        if (type != XmlPullParser.START_TAG) {
            throw new XmlPullParserException(parser.getPositionDescription() + ": <inset> tag requires a 'drawable' attribute or " + "child tag defining a drawable");
        }
        dr = Drawable.createFromXmlInner(r, parser, attrs);
    }
    if (dr == null) {
        Log.w("drawable", "No drawable specified for <inset>");
    }
    mInsetState.mDrawable = dr;
    mInsetState.mInsetLeft = inLeft;
    mInsetState.mInsetRight = inRight;
    mInsetState.mInsetTop = inTop;
    mInsetState.mInsetBottom = inBottom;
    if (dr != null) {
        dr.setCallback(this);
    }
}
Also used : TypedArray(android.content.res.TypedArray) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Aggregations

XmlPullParser (org.xmlpull.v1.XmlPullParser)673 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)623 IOException (java.io.IOException)377 FileInputStream (java.io.FileInputStream)185 FileNotFoundException (java.io.FileNotFoundException)185 File (java.io.File)107 ArrayList (java.util.ArrayList)77 StringReader (java.io.StringReader)65 AttributeSet (android.util.AttributeSet)61 Test (org.junit.Test)57 TypedArray (android.content.res.TypedArray)56 InputStream (java.io.InputStream)48 AtomicFile (android.util.AtomicFile)47 HashMap (java.util.HashMap)45 BridgeXmlBlockParser (com.android.layoutlib.bridge.android.BridgeXmlBlockParser)39 FileReader (java.io.FileReader)36 BufferedInputStream (java.io.BufferedInputStream)30 XmlPullParserFactory (org.xmlpull.v1.XmlPullParserFactory)30 RemoteException (android.os.RemoteException)28 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)28