Java Code Examples for com.google.android.exoplayer2.util.XmlPullParserUtil#getAttributeValue()

The following examples show how to use com.google.android.exoplayer2.util.XmlPullParserUtil#getAttributeValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TtmlDecoder.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private TtsExtent parseTtsExtent(XmlPullParser xmlParser) {
  String ttsExtent = XmlPullParserUtil.getAttributeValue(xmlParser, TtmlNode.ATTR_TTS_EXTENT);
  if (ttsExtent == null) {
    return null;
  }

  Matcher extentMatcher = PIXEL_COORDINATES.matcher(ttsExtent);
  if (!extentMatcher.matches()) {
    Log.w(TAG, "Ignoring non-pixel tts extent: " + ttsExtent);
    return null;
  }
  try {
    int width = Integer.parseInt(extentMatcher.group(1));
    int height = Integer.parseInt(extentMatcher.group(2));
    return new TtsExtent(width, height);
  } catch (NumberFormatException e) {
    Log.w(TAG, "Ignoring malformed tts extent: " + ttsExtent);
    return null;
  }
}
 
Example 2
Source File: TtmlDecoder.java    From K-Sonic with MIT License 6 votes vote down vote up
private Map<String, TtmlStyle> parseHeader(XmlPullParser xmlParser,
    Map<String, TtmlStyle> globalStyles, Map<String, TtmlRegion> globalRegions)
    throws IOException, XmlPullParserException {
  do {
    xmlParser.next();
    if (XmlPullParserUtil.isStartTag(xmlParser, TtmlNode.TAG_STYLE)) {
      String parentStyleId = XmlPullParserUtil.getAttributeValue(xmlParser, ATTR_STYLE);
      TtmlStyle style = parseStyleAttributes(xmlParser, new TtmlStyle());
      if (parentStyleId != null) {
        for (String id : parseStyleIds(parentStyleId)) {
          style.chain(globalStyles.get(id));
        }
      }
      if (style.getId() != null) {
        globalStyles.put(style.getId(), style);
      }
    } else if (XmlPullParserUtil.isStartTag(xmlParser, TtmlNode.TAG_REGION)) {
      Pair<String, TtmlRegion> ttmlRegionInfo = parseRegionAttributes(xmlParser);
      if (ttmlRegionInfo != null) {
        globalRegions.put(ttmlRegionInfo.first, ttmlRegionInfo.second);
      }
    }
  } while (!XmlPullParserUtil.isEndTag(xmlParser, TtmlNode.TAG_HEAD));
  return globalStyles;
}
 
Example 3
Source File: TtmlDecoder.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private TtsExtent parseTtsExtent(XmlPullParser xmlParser) {
  String ttsExtent = XmlPullParserUtil.getAttributeValue(xmlParser, TtmlNode.ATTR_TTS_EXTENT);
  if (ttsExtent == null) {
    return null;
  }

  Matcher extentMatcher = PIXEL_COORDINATES.matcher(ttsExtent);
  if (!extentMatcher.matches()) {
    Log.w(TAG, "Ignoring non-pixel tts extent: " + ttsExtent);
    return null;
  }
  try {
    int width = Integer.parseInt(extentMatcher.group(1));
    int height = Integer.parseInt(extentMatcher.group(2));
    return new TtsExtent(width, height);
  } catch (NumberFormatException e) {
    Log.w(TAG, "Ignoring malformed tts extent: " + ttsExtent);
    return null;
  }
}
 
Example 4
Source File: TtmlDecoder.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private TtsExtent parseTtsExtent(XmlPullParser xmlParser) {
  String ttsExtent = XmlPullParserUtil.getAttributeValue(xmlParser, TtmlNode.ATTR_TTS_EXTENT);
  if (ttsExtent == null) {
    return null;
  }

  Matcher extentMatcher = PIXEL_COORDINATES.matcher(ttsExtent);
  if (!extentMatcher.matches()) {
    Log.w(TAG, "Ignoring non-pixel tts extent: " + ttsExtent);
    return null;
  }
  try {
    int width = Integer.parseInt(extentMatcher.group(1));
    int height = Integer.parseInt(extentMatcher.group(2));
    return new TtsExtent(width, height);
  } catch (NumberFormatException e) {
    Log.w(TAG, "Ignoring malformed tts extent: " + ttsExtent);
    return null;
  }
}
 
Example 5
Source File: TtmlDecoder.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private Map<String, TtmlStyle> parseHeader(
    XmlPullParser xmlParser,
    Map<String, TtmlStyle> globalStyles,
    CellResolution cellResolution,
    TtsExtent ttsExtent,
    Map<String, TtmlRegion> globalRegions,
    Map<String, String> imageMap)
    throws IOException, XmlPullParserException {
  do {
    xmlParser.next();
    if (XmlPullParserUtil.isStartTag(xmlParser, TtmlNode.TAG_STYLE)) {
      String parentStyleId = XmlPullParserUtil.getAttributeValue(xmlParser, ATTR_STYLE);
      TtmlStyle style = parseStyleAttributes(xmlParser, new TtmlStyle());
      if (parentStyleId != null) {
        for (String id : parseStyleIds(parentStyleId)) {
          style.chain(globalStyles.get(id));
        }
      }
      if (style.getId() != null) {
        globalStyles.put(style.getId(), style);
      }
    } else if (XmlPullParserUtil.isStartTag(xmlParser, TtmlNode.TAG_REGION)) {
      TtmlRegion ttmlRegion = parseRegionAttributes(xmlParser, cellResolution, ttsExtent);
      if (ttmlRegion != null) {
        globalRegions.put(ttmlRegion.id, ttmlRegion);
      }
    } else if (XmlPullParserUtil.isStartTag(xmlParser, TtmlNode.TAG_METADATA)) {
      parseMetadata(xmlParser, imageMap);
    }
  } while (!XmlPullParserUtil.isEndTag(xmlParser, TtmlNode.TAG_HEAD));
  return globalStyles;
}
 
Example 6
Source File: TtmlDecoder.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private void parseMetadata(XmlPullParser xmlParser, Map<String, String> imageMap)
    throws IOException, XmlPullParserException {
  do {
    xmlParser.next();
    if (XmlPullParserUtil.isStartTag(xmlParser, TtmlNode.TAG_IMAGE)) {
      String id = XmlPullParserUtil.getAttributeValue(xmlParser, "id");
      if (id != null) {
        String encodedBitmapData = xmlParser.nextText();
        imageMap.put(id, encodedBitmapData);
      }
    }
  } while (!XmlPullParserUtil.isEndTag(xmlParser, TtmlNode.TAG_METADATA));
}
 
Example 7
Source File: TtmlDecoder.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private Map<String, TtmlStyle> parseHeader(
    XmlPullParser xmlParser,
    Map<String, TtmlStyle> globalStyles,
    Map<String, TtmlRegion> globalRegions,
    CellResolution cellResolution)
    throws IOException, XmlPullParserException {
  do {
    xmlParser.next();
    if (XmlPullParserUtil.isStartTag(xmlParser, TtmlNode.TAG_STYLE)) {
      String parentStyleId = XmlPullParserUtil.getAttributeValue(xmlParser, ATTR_STYLE);
      TtmlStyle style = parseStyleAttributes(xmlParser, new TtmlStyle());
      if (parentStyleId != null) {
        for (String id : parseStyleIds(parentStyleId)) {
          style.chain(globalStyles.get(id));
        }
      }
      if (style.getId() != null) {
        globalStyles.put(style.getId(), style);
      }
    } else if (XmlPullParserUtil.isStartTag(xmlParser, TtmlNode.TAG_REGION)) {
      TtmlRegion ttmlRegion = parseRegionAttributes(xmlParser, cellResolution);
      if (ttmlRegion != null) {
        globalRegions.put(ttmlRegion.id, ttmlRegion);
      }
    }
  } while (!XmlPullParserUtil.isEndTag(xmlParser, TtmlNode.TAG_HEAD));
  return globalStyles;
}
 
Example 8
Source File: TtmlDecoder.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private Map<String, TtmlStyle> parseHeader(
    XmlPullParser xmlParser,
    Map<String, TtmlStyle> globalStyles,
    Map<String, TtmlRegion> globalRegions,
    CellResolution cellResolution)
    throws IOException, XmlPullParserException {
  do {
    xmlParser.next();
    if (XmlPullParserUtil.isStartTag(xmlParser, TtmlNode.TAG_STYLE)) {
      String parentStyleId = XmlPullParserUtil.getAttributeValue(xmlParser, ATTR_STYLE);
      TtmlStyle style = parseStyleAttributes(xmlParser, new TtmlStyle());
      if (parentStyleId != null) {
        for (String id : parseStyleIds(parentStyleId)) {
          style.chain(globalStyles.get(id));
        }
      }
      if (style.getId() != null) {
        globalStyles.put(style.getId(), style);
      }
    } else if (XmlPullParserUtil.isStartTag(xmlParser, TtmlNode.TAG_REGION)) {
      TtmlRegion ttmlRegion = parseRegionAttributes(xmlParser, cellResolution);
      if (ttmlRegion != null) {
        globalRegions.put(ttmlRegion.id, ttmlRegion);
      }
    }
  } while (!XmlPullParserUtil.isEndTag(xmlParser, TtmlNode.TAG_HEAD));
  return globalStyles;
}
 
Example 9
Source File: TtmlDecoder.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private Map<String, TtmlStyle> parseHeader(
    XmlPullParser xmlParser,
    Map<String, TtmlStyle> globalStyles,
    CellResolution cellResolution,
    TtsExtent ttsExtent,
    Map<String, TtmlRegion> globalRegions,
    Map<String, String> imageMap)
    throws IOException, XmlPullParserException {
  do {
    xmlParser.next();
    if (XmlPullParserUtil.isStartTag(xmlParser, TtmlNode.TAG_STYLE)) {
      String parentStyleId = XmlPullParserUtil.getAttributeValue(xmlParser, ATTR_STYLE);
      TtmlStyle style = parseStyleAttributes(xmlParser, new TtmlStyle());
      if (parentStyleId != null) {
        for (String id : parseStyleIds(parentStyleId)) {
          style.chain(globalStyles.get(id));
        }
      }
      if (style.getId() != null) {
        globalStyles.put(style.getId(), style);
      }
    } else if (XmlPullParserUtil.isStartTag(xmlParser, TtmlNode.TAG_REGION)) {
      TtmlRegion ttmlRegion = parseRegionAttributes(xmlParser, cellResolution, ttsExtent);
      if (ttmlRegion != null) {
        globalRegions.put(ttmlRegion.id, ttmlRegion);
      }
    } else if (XmlPullParserUtil.isStartTag(xmlParser, TtmlNode.TAG_METADATA)) {
      parseMetadata(xmlParser, imageMap);
    }
  } while (!XmlPullParserUtil.isEndTag(xmlParser, TtmlNode.TAG_HEAD));
  return globalStyles;
}
 
Example 10
Source File: TtmlDecoder.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void parseMetadata(XmlPullParser xmlParser, Map<String, String> imageMap)
    throws IOException, XmlPullParserException {
  do {
    xmlParser.next();
    if (XmlPullParserUtil.isStartTag(xmlParser, TtmlNode.TAG_IMAGE)) {
      String id = XmlPullParserUtil.getAttributeValue(xmlParser, "id");
      if (id != null) {
        String encodedBitmapData = xmlParser.nextText();
        imageMap.put(id, encodedBitmapData);
      }
    }
  } while (!XmlPullParserUtil.isEndTag(xmlParser, TtmlNode.TAG_METADATA));
}
 
Example 11
Source File: TtmlDecoder.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private Map<String, TtmlStyle> parseHeader(
    XmlPullParser xmlParser,
    Map<String, TtmlStyle> globalStyles,
    CellResolution cellResolution,
    TtsExtent ttsExtent,
    Map<String, TtmlRegion> globalRegions,
    Map<String, String> imageMap)
    throws IOException, XmlPullParserException {
  do {
    xmlParser.next();
    if (XmlPullParserUtil.isStartTag(xmlParser, TtmlNode.TAG_STYLE)) {
      String parentStyleId = XmlPullParserUtil.getAttributeValue(xmlParser, ATTR_STYLE);
      TtmlStyle style = parseStyleAttributes(xmlParser, new TtmlStyle());
      if (parentStyleId != null) {
        for (String id : parseStyleIds(parentStyleId)) {
          style.chain(globalStyles.get(id));
        }
      }
      if (style.getId() != null) {
        globalStyles.put(style.getId(), style);
      }
    } else if (XmlPullParserUtil.isStartTag(xmlParser, TtmlNode.TAG_REGION)) {
      TtmlRegion ttmlRegion = parseRegionAttributes(xmlParser, cellResolution, ttsExtent);
      if (ttmlRegion != null) {
        globalRegions.put(ttmlRegion.id, ttmlRegion);
      }
    } else if (XmlPullParserUtil.isStartTag(xmlParser, TtmlNode.TAG_METADATA)) {
      parseMetadata(xmlParser, imageMap);
    }
  } while (!XmlPullParserUtil.isEndTag(xmlParser, TtmlNode.TAG_HEAD));
  return globalStyles;
}
 
Example 12
Source File: TtmlDecoder.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void parseMetadata(XmlPullParser xmlParser, Map<String, String> imageMap)
    throws IOException, XmlPullParserException {
  do {
    xmlParser.next();
    if (XmlPullParserUtil.isStartTag(xmlParser, TtmlNode.TAG_IMAGE)) {
      String id = XmlPullParserUtil.getAttributeValue(xmlParser, "id");
      if (id != null) {
        String encodedBitmapData = xmlParser.nextText();
        imageMap.put(id, encodedBitmapData);
      }
    }
  } while (!XmlPullParserUtil.isEndTag(xmlParser, TtmlNode.TAG_METADATA));
}