Java Code Examples for com.google.android.exoplayer2.util.Util#splitAtFirst()

The following examples show how to use com.google.android.exoplayer2.util.Util#splitAtFirst() . 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: DefaultTrackSelector.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a score for how well a language specified in a {@link Format} matches a given language.
 *
 * @param format The {@link Format}.
 * @param language The language, or null.
 * @param allowUndeterminedFormatLanguage Whether matches with an empty or undetermined format
 *     language tag are allowed.
 * @return A score of 4 if the languages match fully, a score of 3 if the languages match partly,
 *     a score of 2 if the languages don't match but belong to the same main language, a score of
 *     1 if the format language is undetermined and such a match is allowed, and a score of 0 if
 *     the languages don't match at all.
 */
protected static int getFormatLanguageScore(
    Format format, @Nullable String language, boolean allowUndeterminedFormatLanguage) {
  if (!TextUtils.isEmpty(language) && language.equals(format.language)) {
    // Full literal match of non-empty languages, including matches of an explicit "und" query.
    return 4;
  }
  language = normalizeUndeterminedLanguageToNull(language);
  String formatLanguage = normalizeUndeterminedLanguageToNull(format.language);
  if (formatLanguage == null || language == null) {
    // At least one of the languages is undetermined.
    return allowUndeterminedFormatLanguage && formatLanguage == null ? 1 : 0;
  }
  if (formatLanguage.startsWith(language) || language.startsWith(formatLanguage)) {
    // Partial match where one language is a subset of the other (e.g. "zh-hans" and "zh-hans-hk")
    return 3;
  }
  String formatMainLanguage = Util.splitAtFirst(formatLanguage, "-")[0];
  String queryMainLanguage = Util.splitAtFirst(language, "-")[0];
  if (formatMainLanguage.equals(queryMainLanguage)) {
    // Partial match where only the main language tag is the same (e.g. "fr-fr" and "fr-ca")
    return 2;
  }
  return 0;
}
 
Example 2
Source File: DefaultTrackSelector.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a score for how well a language specified in a {@link Format} matches a given language.
 *
 * @param format The {@link Format}.
 * @param language The language, or null.
 * @param allowUndeterminedFormatLanguage Whether matches with an empty or undetermined format
 *     language tag are allowed.
 * @return A score of 4 if the languages match fully, a score of 3 if the languages match partly,
 *     a score of 2 if the languages don't match but belong to the same main language, a score of
 *     1 if the format language is undetermined and such a match is allowed, and a score of 0 if
 *     the languages don't match at all.
 */
protected static int getFormatLanguageScore(
    Format format, @Nullable String language, boolean allowUndeterminedFormatLanguage) {
  if (!TextUtils.isEmpty(language) && language.equals(format.language)) {
    // Full literal match of non-empty languages, including matches of an explicit "und" query.
    return 4;
  }
  language = normalizeUndeterminedLanguageToNull(language);
  String formatLanguage = normalizeUndeterminedLanguageToNull(format.language);
  if (formatLanguage == null || language == null) {
    // At least one of the languages is undetermined.
    return allowUndeterminedFormatLanguage && formatLanguage == null ? 1 : 0;
  }
  if (formatLanguage.startsWith(language) || language.startsWith(formatLanguage)) {
    // Partial match where one language is a subset of the other (e.g. "zh-hans" and "zh-hans-hk")
    return 3;
  }
  String formatMainLanguage = Util.splitAtFirst(formatLanguage, "-")[0];
  String queryMainLanguage = Util.splitAtFirst(language, "-")[0];
  if (formatMainLanguage.equals(queryMainLanguage)) {
    // Partial match where only the main language tag is the same (e.g. "fr-fr" and "fr-ca")
    return 2;
  }
  return 0;
}
 
Example 3
Source File: DefaultTrackSelector.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a score for how well a language specified in a {@link Format} matches a given language.
 *
 * @param format The {@link Format}.
 * @param language The language, or null.
 * @param allowUndeterminedFormatLanguage Whether matches with an empty or undetermined format
 *     language tag are allowed.
 * @return A score of 4 if the languages match fully, a score of 3 if the languages match partly,
 *     a score of 2 if the languages don't match but belong to the same main language, a score of
 *     1 if the format language is undetermined and such a match is allowed, and a score of 0 if
 *     the languages don't match at all.
 */
protected static int getFormatLanguageScore(
    Format format, @Nullable String language, boolean allowUndeterminedFormatLanguage) {
  if (!TextUtils.isEmpty(language) && language.equals(format.language)) {
    // Full literal match of non-empty languages, including matches of an explicit "und" query.
    return 4;
  }
  language = normalizeUndeterminedLanguageToNull(language);
  String formatLanguage = normalizeUndeterminedLanguageToNull(format.language);
  if (formatLanguage == null || language == null) {
    // At least one of the languages is undetermined.
    return allowUndeterminedFormatLanguage && formatLanguage == null ? 1 : 0;
  }
  if (formatLanguage.startsWith(language) || language.startsWith(formatLanguage)) {
    // Partial match where one language is a subset of the other (e.g. "zh-hans" and "zh-hans-hk")
    return 3;
  }
  String formatMainLanguage = Util.splitAtFirst(formatLanguage, "-")[0];
  String queryMainLanguage = Util.splitAtFirst(language, "-")[0];
  if (formatMainLanguage.equals(queryMainLanguage)) {
    // Partial match where only the main language tag is the same (e.g. "fr-fr" and "fr-ca")
    return 2;
  }
  return 0;
}
 
Example 4
Source File: WebvttParserUtil.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Parses a WebVTT timestamp.
 *
 * @param timestamp The timestamp string.
 * @return The parsed timestamp in microseconds.
 * @throws NumberFormatException If the timestamp could not be parsed.
 */
public static long parseTimestampUs(String timestamp) throws NumberFormatException {
  long value = 0;
  String[] parts = Util.splitAtFirst(timestamp, "\\.");
  String[] subparts = Util.split(parts[0], ":");
  for (String subpart : subparts) {
    value = (value * 60) + Long.parseLong(subpart);
  }
  value *= 1000;
  if (parts.length == 2) {
    value += Long.parseLong(parts[1]);
  }
  return value * 1000;
}
 
Example 5
Source File: WebvttCueParser.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the tag name for the given tag contents.
 *
 * @param tagExpression Characters between &lt: and > of a start or end tag.
 * @return The name of tag.
 */
private static String getTagName(String tagExpression) {
  tagExpression = tagExpression.trim();
  if (tagExpression.isEmpty()) {
    return null;
  }
  return Util.splitAtFirst(tagExpression, "[ \\.]")[0];
}
 
Example 6
Source File: WebvttParserUtil.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parses a WebVTT timestamp.
 *
 * @param timestamp The timestamp string.
 * @return The parsed timestamp in microseconds.
 * @throws NumberFormatException If the timestamp could not be parsed.
 */
public static long parseTimestampUs(String timestamp) throws NumberFormatException {
  long value = 0;
  String[] parts = Util.splitAtFirst(timestamp, "\\.");
  String[] subparts = Util.split(parts[0], ":");
  for (String subpart : subparts) {
    value = (value * 60) + Long.parseLong(subpart);
  }
  value *= 1000;
  if (parts.length == 2) {
    value += Long.parseLong(parts[1]);
  }
  return value * 1000;
}
 
Example 7
Source File: WebvttCueParser.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the tag name for the given tag contents.
 *
 * @param tagExpression Characters between &lt: and > of a start or end tag.
 * @return The name of tag.
 */
private static String getTagName(String tagExpression) {
  tagExpression = tagExpression.trim();
  if (tagExpression.isEmpty()) {
    return null;
  }
  return Util.splitAtFirst(tagExpression, "[ \\.]")[0];
}
 
Example 8
Source File: WebvttParserUtil.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parses a WebVTT timestamp.
 *
 * @param timestamp The timestamp string.
 * @return The parsed timestamp in microseconds.
 * @throws NumberFormatException If the timestamp could not be parsed.
 */
public static long parseTimestampUs(String timestamp) throws NumberFormatException {
  long value = 0;
  String[] parts = Util.splitAtFirst(timestamp, "\\.");
  String[] subparts = Util.split(parts[0], ":");
  for (String subpart : subparts) {
    value = (value * 60) + Long.parseLong(subpart);
  }
  value *= 1000;
  if (parts.length == 2) {
    value += Long.parseLong(parts[1]);
  }
  return value * 1000;
}
 
Example 9
Source File: WebvttCueParser.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the tag name for the given tag contents.
 *
 * @param tagExpression Characters between &lt: and > of a start or end tag.
 * @return The name of tag.
 */
private static String getTagName(String tagExpression) {
  tagExpression = tagExpression.trim();
  if (tagExpression.isEmpty()) {
    return null;
  }
  return Util.splitAtFirst(tagExpression, "[ \\.]")[0];
}
 
Example 10
Source File: WebvttParserUtil.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parses a WebVTT timestamp.
 *
 * @param timestamp The timestamp string.
 * @return The parsed timestamp in microseconds.
 * @throws NumberFormatException If the timestamp could not be parsed.
 */
public static long parseTimestampUs(String timestamp) throws NumberFormatException {
  long value = 0;
  String[] parts = Util.splitAtFirst(timestamp, "\\.");
  String[] subparts = Util.split(parts[0], ":");
  for (String subpart : subparts) {
    value = (value * 60) + Long.parseLong(subpart);
  }
  value *= 1000;
  if (parts.length == 2) {
    value += Long.parseLong(parts[1]);
  }
  return value * 1000;
}
 
Example 11
Source File: WebvttCueParser.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the tag name for the given tag contents.
 *
 * @param tagExpression Characters between &lt: and > of a start or end tag.
 * @return The name of tag.
 */
private static String getTagName(String tagExpression) {
  tagExpression = tagExpression.trim();
  if (tagExpression.isEmpty()) {
    return null;
  }
  return Util.splitAtFirst(tagExpression, "[ \\.]")[0];
}
 
Example 12
Source File: WebvttParserUtil.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parses a WebVTT timestamp.
 *
 * @param timestamp The timestamp string.
 * @return The parsed timestamp in microseconds.
 * @throws NumberFormatException If the timestamp could not be parsed.
 */
public static long parseTimestampUs(String timestamp) throws NumberFormatException {
  long value = 0;
  String[] parts = Util.splitAtFirst(timestamp, "\\.");
  String[] subparts = Util.split(parts[0], ":");
  for (String subpart : subparts) {
    value = (value * 60) + Long.parseLong(subpart);
  }
  value *= 1000;
  if (parts.length == 2) {
    value += Long.parseLong(parts[1]);
  }
  return value * 1000;
}
 
Example 13
Source File: WebvttCueParser.java    From MediaSDK with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the tag name for the given tag contents.
 *
 * @param tagExpression Characters between &lt: and > of a start or end tag.
 * @return The name of tag.
 */
private static String getTagName(String tagExpression) {
  tagExpression = tagExpression.trim();
  Assertions.checkArgument(!tagExpression.isEmpty());
  return Util.splitAtFirst(tagExpression, "[ \\.]")[0];
}