@svta/common-media-library
Version:
A common library for media playback in JavaScript
30 lines • 887 B
JavaScript
import { WebVttParser } from './WebVttParser.js';
/**
* Parse a WebVTT string into a WebVttParseResult.
*
* @param text - The WebVTT string to parse.
* @param options - The options to use for the parser.
* @returns The parsed WebVttParseResult.
*
* @group WebVTT
*
* @beta
*
* @example
* {@includeCode ../../test/webvtt/parseWebVtt.test.ts#example}
*/
export async function parseWebVtt(text, options) {
const parser = new WebVttParser(options);
const cues = [];
const regions = [];
const styles = [];
const errors = [];
parser.oncue = cue => cues.push(cue);
parser.onregion = region => regions.push(region);
parser.onstyle = style => styles.push(style);
parser.onparsingerror = error => errors.push(error);
parser.parse(text);
parser.flush();
return { cues, regions, styles, errors };
}
//# sourceMappingURL=parseWebVtt.js.map