@@ -72,6 +72,15 @@ type VideoSourceWithType = {
7272 type ?: string ; // video/webm, video/mp4...
7373} ;
7474
75+ export type VideoTrack = {
76+ src : string ;
77+ kind : 'subtitles' | 'captions' ;
78+ /** https://developer.mozilla.org/en-US/docs/Glossary/BCP_47_language_tag */
79+ srcLang : string ;
80+ label ?: string ;
81+ default ?: boolean ;
82+ } ;
83+
7584export type VideoSource =
7685 | string
7786 | ReadonlyArray < string >
@@ -103,6 +112,8 @@ export type VideoProps = {
103112 onPause ?: ( ) => void ;
104113 onLoad ?: ( ) => void ;
105114 poster ?: string ;
115+ /** text track elements for subtitles and captions */
116+ tracks ?: ReadonlyArray < VideoTrack > ;
106117 children ?: void ;
107118 /** defaults to none */
108119 preload ?: 'none' | 'metadata' | 'auto' ;
@@ -116,13 +127,20 @@ export interface VideoElement extends HTMLDivElement {
116127 /** Stops the video and shows the poster image (if available) */
117128 stop : ( ) => void ;
118129 setCurrentTime : ( time : number ) => void ;
130+ /**
131+ * Sets the display mode of a track by its index.
132+ * - 'showing': track is visible
133+ * - 'disabled': track is inactive
134+ */
135+ setTrackMode : ( index : number , mode : 'showing' | 'disabled' ) => void ;
119136}
120137
121138const Video = React . forwardRef < VideoElement , VideoProps > (
122139 (
123140 {
124141 src,
125142 poster,
143+ tracks,
126144 autoPlay = 'when-loaded' ,
127145 muted = true ,
128146 loop = true ,
@@ -210,6 +228,7 @@ const Video = React.forwardRef<VideoElement, VideoProps>(
210228 disableRemotePlayback
211229 muted = { muted }
212230 loop = { loop }
231+ crossOrigin = { tracks ?. length ? 'anonymous' : undefined }
213232 className = { classNames ( styles . video , mediaStyles . defaultBorderRadius ) }
214233 preload = { preload }
215234 onError = { handleError }
@@ -242,6 +261,16 @@ const Video = React.forwardRef<VideoElement, VideoProps>(
242261 { sources . map ( ( { src, type} , index ) => (
243262 < source key = { index } src = { src } type = { type } />
244263 ) ) }
264+ { tracks ?. map ( ( { src, kind, srcLang, label, default : isDefault } , index ) => (
265+ < track
266+ key = { index }
267+ src = { src }
268+ kind = { kind }
269+ srcLang = { srcLang }
270+ label = { label }
271+ default = { isDefault }
272+ />
273+ ) ) }
245274 </ video >
246275 ) ;
247276
@@ -326,6 +355,13 @@ const Video = React.forwardRef<VideoElement, VideoProps>(
326355 dispatch ( 'stop' ) ;
327356 }
328357 } ;
358+ containerElement . setTrackMode = ( index : number , mode : 'showing' | 'disabled' ) => {
359+ const trackElements = videoRef . current ?. querySelectorAll ( 'track' ) ;
360+ const trackElement = trackElements ?. [ index ] as HTMLTrackElement | undefined ;
361+ if ( trackElement ?. track ) {
362+ trackElement . track . mode = mode ;
363+ }
364+ } ;
329365 }
330366
331367 if ( typeof ref === 'function' ) {
0 commit comments