feat: add subtitles handling + captions core (#692)

This commit is contained in:
Wesley Luyten
2026-03-05 17:11:49 -06:00
committed by GitHub
parent b65d537878
commit 5c116065a9
22 changed files with 674 additions and 105 deletions
@@ -0,0 +1,9 @@
import { CaptionsButtonElement } from '../../ui/captions-button/captions-button-element';
customElements.define(CaptionsButtonElement.tagName, CaptionsButtonElement);
declare global {
interface HTMLElementTagNameMap {
[CaptionsButtonElement.tagName]: CaptionsButtonElement;
}
}
+1
View File
@@ -15,6 +15,7 @@ export * from './store/provider-mixin';
export * from './store/types';
// UI Components
export { BufferingIndicatorElement } from './ui/buffering-indicator/buffering-indicator-element';
export { CaptionsButtonElement } from './ui/captions-button/captions-button-element';
export { ControlsElement } from './ui/controls/controls-element';
export { ControlsGroupElement } from './ui/controls/controls-group-element';
export { FullscreenButtonElement } from './ui/fullscreen-button/fullscreen-button-element';
+1 -1
View File
@@ -13,7 +13,7 @@ export class HlsVideo extends HlsCustomMedia {
// are appended after the custom element is created, we need to
// attach the native element to the Media API after the native element
// is appended to the DOM. This is currently not supported.
this.attach(this.nativeEl);
this.attach(this.target);
}
attributeChangedCallback(attrName: string, oldValue: string | null, newValue: string | null): void {
@@ -0,0 +1,18 @@
import { CaptionsButtonCore, CaptionsButtonDataAttrs, type MediaTextTrackState } from '@videojs/core';
import { selectTextTrack } from '@videojs/core/dom';
import { playerContext } from '../../player/context';
import { PlayerController } from '../../player/player-controller';
import { MediaButtonElement } from '../media-button-element';
export class CaptionsButtonElement extends MediaButtonElement<CaptionsButtonCore> {
static readonly tagName = 'media-captions-button';
protected readonly core = new CaptionsButtonCore();
protected readonly stateAttrMap = CaptionsButtonDataAttrs;
protected readonly mediaState = new PlayerController(this, playerContext, selectTextTrack);
protected activate(state: MediaTextTrackState): void {
this.core.toggle(state);
}
}