# WebvttParserUtil

Artifact: [androidx.media3:media3-extractor](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/extractor/text/webvtt/WebvttParserUtil.java+class:androidx.media3.extractor.text.webvtt.WebvttParserUtil)

*** ** * ** ***


```
@UnstableApi
public final class WebvttParserUtil
```

<br />

*** ** * ** ***

Utility methods for parsing WebVTT data.

## Summary

| ### Public methods |
|---|---|
| `static @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/util/regex/Matcher.html` | `https://developer.android.com/reference/androidx/media3/extractor/text/webvtt/WebvttParserUtil#findNextCueHeader(androidx.media3.common.util.ParsableByteArray)(https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray input)` Reads lines up to and including the next WebVTT cue header. |
| `static boolean` | `https://developer.android.com/reference/androidx/media3/extractor/text/webvtt/WebvttParserUtil#isWebvttHeaderLine(androidx.media3.common.util.ParsableByteArray)(https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray input)` Returns whether the given input is the first line of a WebVTT file. |
| `static float` | `https://developer.android.com/reference/androidx/media3/extractor/text/webvtt/WebvttParserUtil#parsePercentage(java.lang.String)(https://developer.android.com/reference/java/lang/String.html s)` Parses a percentage string. |
| `static long` | `https://developer.android.com/reference/androidx/media3/extractor/text/webvtt/WebvttParserUtil#parseTimestampUs(java.lang.String)(https://developer.android.com/reference/java/lang/String.html timestamp)` Parses a WebVTT timestamp. |
| `static void` | `https://developer.android.com/reference/androidx/media3/extractor/text/webvtt/WebvttParserUtil#validateWebvttHeaderLine(androidx.media3.common.util.ParsableByteArray)(https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray input)` 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 |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray input` | The input from which lines should be read. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/util/regex/Matcher.html` | A `https://developer.android.com/reference/java/util/regex/Matcher.html` 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 |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray input` | The input from which the line should be read. |

### parsePercentage

```
public static float parsePercentage(String s)
```

Parses a percentage string.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html s` | The percentage string. |

| Returns |
|---|---|
| `float` | The parsed value, where 1.0 represents 100%. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NumberFormatException.html` | If the percentage could not be parsed. |

### parseTimestampUs

```
public static long parseTimestampUs(String timestamp)
```

Parses a WebVTT timestamp.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html timestamp` | The timestamp string. |

| Returns |
|---|---|
| `long` | The parsed timestamp in microseconds. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | 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 |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray input` | The input from which the line should be read. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/ParserException` | If the line isn't the start of a valid WebVTT file. |