WebvttParserUtil


@UnstableApi
public final class WebvttParserUtil


Utility methods for parsing WebVTT data.

Summary

Public methods

static @Nullable Matcher

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

static boolean

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

static float

Parses a percentage string.

static long

Parses a WebVTT timestamp.

static void

Reads and validates the first line of a WebVTT file.

Public methods

findNextCueHeader

public static @Nullable Matcher findNextCueHeader(ParsableByteArray input)

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

Parameters
ParsableByteArray input

The input from which lines should be read.

Returns
@Nullable 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

public static boolean isWebvttHeaderLine(ParsableByteArray input)

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

Parameters
ParsableByteArray input

The input from which the line should be read.

parsePercentage

public static float parsePercentage(String s)

Parses a percentage string.

Parameters
String s

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

public static long parseTimestampUs(String timestamp)

Parses a WebVTT timestamp.

Parameters
String timestamp

The timestamp string.

Returns
long

The parsed timestamp in microseconds.

Throws
java.lang.NumberFormatException

If the timestamp could not be parsed.

validateWebvttHeaderLine

public static void validateWebvttHeaderLine(ParsableByteArray input)

Reads and validates the first line of a WebVTT file.

Parameters
ParsableByteArray input

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.