Skip to content

feat(subtitle): add provider caption support for vimeo, dailymotion and youtube#222

Open
klocus wants to merge 2 commits into
vlitejs:mainfrom
klocus:feat/provider-captions
Open

feat(subtitle): add provider caption support for vimeo, dailymotion and youtube#222
klocus wants to merge 2 commits into
vlitejs:mainfrom
klocus:feat/provider-captions

Conversation

@klocus

@klocus klocus commented Jun 22, 2026

Copy link
Copy Markdown

Summary

Extend the subtitle plugin with provider caption support for Vimeo, Dailymotion, and YouTube. Provider captions render inside their iframes via the provider SDK, while HTML5 keeps the native TextTrack API.

Changes

Core

  • src/plugins/subtitle/subtitle.ts — Provider-aware two-path model using duck-typed capability probing (typeof player.getTextTracks === 'function'). Local NormalizedTextTrack type replaces TextTrack, extracted cacheDomElements() helper, providerTracksInitialized guard + texttracksready event listener for YouTube/Dailymotion late-load recovery.
  • src/providers/vimeo/vimeo.tsgetTextTracks(), enableTextTrack(), disableTextTrack() via Vimeo SDK.
  • src/providers/dailymotion/dailymotion.tsgetTextTracks() (uses getState()videoSubtitlesList, Intl.DisplayNames for labels), enableTextTrack(), disableTextTrack() via Dailymotion SDK. Dispatches texttracksready event when captions module loads.
  • src/providers/youtube/youtube.tscaptionsModuleReady promise resolved in onApiChange(), getTextTracks() (race vs 5s timeout), enableTextTrack(), disableTextTrack() via YouTube IFrame API. Dispatches texttracksready event when captions module loads.

Docs & Examples

  • src/plugins/subtitle/README.md — Updated provider row and Vimeo/Dailymotion/YouTube usage sections.
  • examples/{vimeo,dailymotion,youtube}/config.js — Subtitle plugin registration + trackenabled/trackdisabled listeners.
  • examples/{vimeo,dailymotion,youtube}/index.html — Updated demo video IDs to captioned content.

How it works

The subtitle plugin probes the player instance for getTextTracks / enableTextTrack / disableTextTrack methods. If present (Vimeo, Dailymotion, YouTube), it uses the provider SDK path where captions render inside the provider iframe. Otherwise (HTML5), it uses the native TextTrack API with the .v-captions overlay.

For YouTube, the captions module loads asynchronously (onApiChange). The plugin handles this with a texttracksready event and re-initializes tracks when the module becomes available.

Test plan

  • npx @biomejs/biome check passes on all changed files
  • npx tsc --noEmit passes (no new errors)
  • Manual verification in browser: Vimeo, Dailymotion, YouTube examples show CC button, language list, and rendered captions

Non-breaking

HTML5 subtitle functionality is unchanged. Provider support is additive — the plugin falls back gracefully when provider methods are absent.

…nd youtube

Extend the subtitle plugin with a provider-aware two-path model using
duck-typed capability probing. Provider SDKs (Vimeo, Dailymotion, YouTube)
render captions inside their iframes via getTextTracks/enableTextTrack/
disableTextTrack methods, while HTML5 keeps the native TextTrack API.
@vercel

vercel Bot commented Jun 22, 2026

Copy link
Copy Markdown

@klocus is attempting to deploy a commit to the Vlitejs Team on Vercel.

A member of the Team first needs to authorize it.

…lable

Dailymotion loads subtitles asynchronously after playback starts,
not at onReady time. Listen for the SDK's subtitlesavailable event
and dispatch texttracksready so the subtitle plugin can render the CC UI.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant