feat(subtitle): add provider caption support for vimeo, dailymotion and youtube#222
Open
klocus wants to merge 2 commits into
Open
feat(subtitle): add provider caption support for vimeo, dailymotion and youtube#222klocus wants to merge 2 commits into
klocus wants to merge 2 commits into
Conversation
…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.
|
@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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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'). LocalNormalizedTextTracktype replacesTextTrack, extractedcacheDomElements()helper,providerTracksInitializedguard +texttracksreadyevent listener for YouTube/Dailymotion late-load recovery.src/providers/vimeo/vimeo.ts—getTextTracks(),enableTextTrack(),disableTextTrack()via Vimeo SDK.src/providers/dailymotion/dailymotion.ts—getTextTracks()(usesgetState()→videoSubtitlesList,Intl.DisplayNamesfor labels),enableTextTrack(),disableTextTrack()via Dailymotion SDK. Dispatchestexttracksreadyevent when captions module loads.src/providers/youtube/youtube.ts—captionsModuleReadypromise resolved inonApiChange(),getTextTracks()(race vs 5s timeout),enableTextTrack(),disableTextTrack()via YouTube IFrame API. Dispatchestexttracksreadyevent 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/trackdisabledlisteners.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/disableTextTrackmethods. If present (Vimeo, Dailymotion, YouTube), it uses the provider SDK path where captions render inside the provider iframe. Otherwise (HTML5), it uses the nativeTextTrackAPI with the.v-captionsoverlay.For YouTube, the captions module loads asynchronously (
onApiChange). The plugin handles this with atexttracksreadyevent and re-initializes tracks when the module becomes available.Test plan
npx @biomejs/biome checkpasses on all changed filesnpx tsc --noEmitpasses (no new errors)Non-breaking
HTML5 subtitle functionality is unchanged. Provider support is additive — the plugin falls back gracefully when provider methods are absent.