Skip to content

Adapter: Cue Parser

Cue Parsers and Recipe: Register a Custom Cue Parser cover this port in depth. This page is the terse reference.

The interface

TypeScript
interface ICueParser<T = unknown> {
readonly id: string;
canParse(url: string, contentType?: string): boolean;
parse(raw: string, opts?: { baseUrl?: string }): CueList<T>;
}

Shipped implementations

vttSubtitleParser (.vtt, inline <b>/<i>/<u> preserved, cue-setting alignment), spriteVttParser (sprite-sheet crops via #xywh= fragments, gated to URLs that hint at sprites), lrcParser (.lrc, plain or word-level enhanced LRC).

Rules & restrictions

  • CueParserRegistry.resolve(url, contentType?) walks parsers most-recently-registered first and returns the first match. Registering a custom parser for an extension a built-in already claims wins resolution without disabling the built-in for other URLs.
  • Returning true from canParse is a commitment, the registry doesn’t fall through to the next parser if parse() then throws.

How to extend it

TypeScript
import nmplayer from '@nomercy-entertainment/nomercy-video-player'; // nomercy-music-player's factory works identically
import type { ICueParser } from '@nomercy-entertainment/nomercy-player-core';
import { createCueList } from '@nomercy-entertainment/nomercy-player-core';

const player = nmplayer('player');

const srtParser: ICueParser<{ text: string }> = {
id: 'srt',
canParse: url => url.endsWith('.srt'),
parse: raw => createCueList(parseSrtBlocks(raw)),
};

player.setup({ cueParsers: [srtParser] }); // registered after the built-ins, so it wins resolution
// or at runtime: player.registerCueParser(srtParser); // pass prepend: true to rank it BELOW the built-ins instead

Next steps