# WebvttParserUtil

# 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)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/media3/extractor/text/webvtt/WebvttParserUtil "View this page in Java")

<br />

```
@UnstableApi
class WebvttParserUtil
```

<br />

*** ** * ** ***

Utility methods for parsing WebVTT data.

## Summary

|                                       ### Public functions                                        |
|---------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static `[Matcher](https://developer.android.com/reference/java/util/regex/Matcher.html)`?`  | [findNextCueHeader](https://developer.android.com/reference/kotlin/androidx/media3/extractor/text/webvtt/WebvttParserUtil#findNextCueHeader(androidx.media3.common.util.ParsableByteArray))`(input: `[ParsableByteArray](https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableByteArray)`!)` Reads lines up to and including the next WebVTT cue header.           |
| `java-static `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | [isWebvttHeaderLine](https://developer.android.com/reference/kotlin/androidx/media3/extractor/text/webvtt/WebvttParserUtil#isWebvttHeaderLine(androidx.media3.common.util.ParsableByteArray))`(input: `[ParsableByteArray](https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableByteArray)`!)` Returns whether the given input is the first line of a WebVTT file. |
| `java-static `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)     | [parsePercentage](https://developer.android.com/reference/kotlin/androidx/media3/extractor/text/webvtt/WebvttParserUtil#parsePercentage(java.lang.String))`(s: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!)` Parses a percentage string.                                                                                                                |
| `java-static `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)       | [parseTimestampUs](https://developer.android.com/reference/kotlin/androidx/media3/extractor/text/webvtt/WebvttParserUtil#parseTimestampUs(java.lang.String))`(timestamp: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!)` Parses a WebVTT timestamp.                                                                                                       |
| `java-static `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)       | [validateWebvttHeaderLine](https://developer.android.com/reference/kotlin/androidx/media3/extractor/text/webvtt/WebvttParserUtil#validateWebvttHeaderLine(androidx.media3.common.util.ParsableByteArray))`(input: `[ParsableByteArray](https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableByteArray)`!)` 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](https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableByteArray)`!` | The input from which lines should be read. |

|                                      Returns                                       |
|------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Matcher](https://developer.android.com/reference/java/util/regex/Matcher.html)`?` | A[Matcher](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

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

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

|                                                          Parameters                                                           |
|-------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------|
| `input: `[ParsableByteArray](https://developer.android.com/reference/kotlin/androidx/media3/common/util/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](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!` | The percentage string. |

|                                     Returns                                     |
|---------------------------------------------------------------------------------|----------------------------------------------|
| [Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | The parsed value, where 1.0 represents 100%. |

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

### parseTimestampUs

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

Parses a WebVTT timestamp.  

|                                            Parameters                                             |
|---------------------------------------------------------------------------------------------------|-----------------------|
| `timestamp: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!` | The timestamp string. |

|                                    Returns                                    |
|-------------------------------------------------------------------------------|---------------------------------------|
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | The parsed timestamp in microseconds. |

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

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