Esempio n. 1
0
  private boolean parsePlayListInfo(ElementBuilder builder, String line) {
    int programId = -1;
    int bandWidth = -1;
    String codec = "";
    String attributesList = line.substring(line.indexOf(":"));

    // Iterate through the attributes string, chopping it down until we have all the values
    try {
      while (attributesList.length() > 0) {
        // Skip the initial : or the last delimiting comma
        attributesList = attributesList.substring(1);
        String name = attributesList.substring(0, attributesList.indexOf('='));
        int indexOfEquals = attributesList.indexOf('=');
        attributesList = attributesList.substring(indexOfEquals + 1);
        String value;

        if (attributesList.charAt(0) == '"') {
          // String component.
          // Skip the initial "
          attributesList = attributesList.substring(1);
          int indexOfQuote = attributesList.indexOf('"');
          value = attributesList.substring(0, indexOfQuote);
          attributesList = attributesList.substring(indexOfQuote + 1);
        } else {
          int indexOfComma = attributesList.indexOf(',');
          indexOfComma = indexOfComma != -1 ? indexOfComma : attributesList.length();
          value = attributesList.substring(0, indexOfComma);
          attributesList = attributesList.substring(indexOfComma);
        }

        // Check to see whether our kvp is important to us

        if (name.contentEquals(PROGRAM_ID)) {
          programId = Integer.parseInt(value);
        } else if (name.contentEquals(CODECS)) {
          codec = value;
        } else if (name.contentEquals(BANDWIDTH)) {
          bandWidth = Integer.parseInt(value);
        } else {
          log.fine("Unhandled STREAM-INF attribute " + name + " " + value);
        }
      }
    } catch (NumberFormatException e) {
      return false;
    } catch (IndexOutOfBoundsException e) {
      return false;
    }

    builder.playList(programId, bandWidth, codec);

    return true;
  }