WebvttParserUtil


@UnstableApi
class WebvttParserUtil


Utility methods for parsing WebVTT data.

Summary

Public functions

java-static Matcher?

Reads lines up to and including the next WebVTT cue header.

java-static Boolean

Returns whether the given input is the first line of a WebVTT file.

java-static Float

Parses a percentage string.

java-static Long
parseTimestampUs(timestamp: String!)

Parses a WebVTT timestamp.

java-static Unit

Reads and validates the first line of a WebVTT file.

Public functions

findNextCueHeader

java-static fun findNextCueHeader(input: ParsableByteArray!): Matcher?

Reads lines up to and including the next WebVTT cue header.

Parameters
input: ParsableByteArray!

The input from which lines should be read.

Returns
Matcher?

A Matcher for the WebVTT cue header, or null if the end of the input was reached without a cue header being found. In the case that a cue header is found, groups 1, 2 and 3 of the returned matcher contain the start time, end time and settings list.

isWebvttHeaderLine

java-static fun isWebvttHeaderLine(input: ParsableByteArray!): Boolean

Returns whether the given input is the first line of a WebVTT file.

Parameters
input: ParsableByteArray!

The input from which the line should be read.

parsePercentage

java-static fun parsePercentage(s: String!): Float

Parses a percentage string.

Parameters
s: String!

The percentage string.

Returns
Float

The parsed value, where 1.0 represents 100%.

Throws
java.lang.NumberFormatException

If the percentage could not be parsed.

parseTimestampUs

java-static fun parseTimestampUs(timestamp: String!): Long

Parses a WebVTT timestamp.

Parameters
timestamp: String!

The timestamp string.

Returns
Long

The parsed timestamp in microseconds.

Throws
java.lang.NumberFormatException

If the timestamp could not be parsed.

validateWebvttHeaderLine

java-static fun validateWebvttHeaderLine(input: ParsableByteArray!): Unit

Reads and validates the first line of a WebVTT file.

Parameters
input: ParsableByteArray!

The input from which the line should be read.

Throws
androidx.media3.common.ParserException

If the line isn't the start of a valid WebVTT file.