示例#1
0
 private TtmlNode parseNode(XmlPullParser parser, TtmlNode parent) throws ParserException {
   long duration = 0;
   long startTime = TtmlNode.UNDEFINED_TIME;
   long endTime = TtmlNode.UNDEFINED_TIME;
   String[] styleIds = null;
   int attributeCount = parser.getAttributeCount();
   TtmlStyle style = parseStyleAttributes(parser, null);
   for (int i = 0; i < attributeCount; i++) {
     String attr = ParserUtil.removeNamespacePrefix(parser.getAttributeName(i));
     String value = parser.getAttributeValue(i);
     if (attr.equals(ATTR_BEGIN)) {
       startTime =
           parseTimeExpression(value, DEFAULT_FRAMERATE, DEFAULT_SUBFRAMERATE, DEFAULT_TICKRATE);
     } else if (attr.equals(ATTR_END)) {
       endTime =
           parseTimeExpression(value, DEFAULT_FRAMERATE, DEFAULT_SUBFRAMERATE, DEFAULT_TICKRATE);
     } else if (attr.equals(ATTR_DURATION)) {
       duration =
           parseTimeExpression(value, DEFAULT_FRAMERATE, DEFAULT_SUBFRAMERATE, DEFAULT_TICKRATE);
     } else if (attr.equals(ATTR_STYLE)) {
       // IDREFS: potentially multiple space delimited ids
       String[] ids = parseStyleIds(value);
       if (ids.length > 0) {
         styleIds = ids;
       }
     } else {
       // Do nothing.
     }
   }
   if (parent != null && parent.startTimeUs != TtmlNode.UNDEFINED_TIME) {
     if (startTime != TtmlNode.UNDEFINED_TIME) {
       startTime += parent.startTimeUs;
     }
     if (endTime != TtmlNode.UNDEFINED_TIME) {
       endTime += parent.startTimeUs;
     }
   }
   if (endTime == TtmlNode.UNDEFINED_TIME) {
     if (duration > 0) {
       // Infer the end time from the duration.
       endTime = startTime + duration;
     } else if (parent != null && parent.endTimeUs != TtmlNode.UNDEFINED_TIME) {
       // If the end time remains unspecified, then it should be inherited from the parent.
       endTime = parent.endTimeUs;
     }
   }
   return TtmlNode.buildNode(parser.getName(), startTime, endTime, style, styleIds);
 }