{"library":"media-captions","title":"Media Captions Parser & Renderer","description":"The `media-captions` library is a robust, lightweight, and zero-dependency solution for parsing and rendering various media caption formats on the modern web. It supports SubRip (SRT), WebVTT (VTT), and SubStation Alpha/Advanced SubStation Alpha (SSA/ASS) formats. Currently at version 0.0.18, it is actively maintained by the Vidstack team as a core component of their media player ecosystem, which ensures consistent and accessible caption experiences across different browsers and platforms, addressing limitations often found with native browser captioning. Key differentiators include its modular architecture for tree-shaking, a compact 5KB footprint, lazy-loaded parsers, efficient CSS-based style application, and adherence to WebVTT rendering specifications for features like regions, cues, and roll-up captions. It is built with TypeScript and designed to work both server-side and client-side, requiring Node.js version 16 or higher.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install media-captions"],"cli":null},"imports":["import { createParser } from 'media-captions';","import { SRTParser } from 'media-captions';","import { CaptionsRenderer } from 'media-captions';","import type { CaptionsParser } from 'media-captions';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { createParser, SRTParser } from 'media-captions';\n\nasync function parseSRTString() {\n  const srtContent = `1\n00:00:00,500 --> 00:00:02,500\nHello, world!\n\n2\n00:00:03,000 --> 00:00:05,000\nThis is a test caption.`;\n\n  // Using createParser factory function\n  const parser = createParser('srt');\n  const cuesFromFactory = await parser.parse(srtContent);\n  console.log('Cues from factory:', cuesFromFactory);\n\n  // Alternatively, instantiate a specific parser directly\n  const srtParser = new SRTParser();\n  const cuesFromDirectInstance = await srtParser.parse(srtContent);\n  console.log('Cues from direct instance:', cuesFromDirectInstance);\n\n  // Each cue is a VTTCue-like object\n  if (cuesFromFactory.length > 0) {\n    console.log(`First cue text: ${cuesFromFactory[0].text}`);\n    console.log(`First cue start time: ${cuesFromFactory[0].startTime}`);\n  }\n\n  // To render these, you would typically use a CaptionsRenderer instance\n  // const renderer = new CaptionsRenderer(videoElement);\n  // renderer.addCues(cuesFromFactory);\n  // renderer.render(currentTime);\n}\n\nparseSRTString().catch(console.error);","lang":"typescript","description":"Demonstrates how to parse an SRT caption string using both the `createParser` factory and directly instantiating `SRTParser`, then logs the resulting cue objects. It also briefly mentions how a `CaptionsRenderer` would be used.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}