mirror of
https://github.com/zoriya/react-native-video.git
synced 2025-12-06 07:16:12 +00:00
Add text track handling
This commit is contained in:
@@ -68,7 +68,15 @@ class VideoPlayer extends VideoPlayerEvents implements VideoPlayerBase {
|
|||||||
|
|
||||||
constructor(source: VideoSource | VideoConfig | VideoPlayerSource) {
|
constructor(source: VideoSource | VideoConfig | VideoPlayerSource) {
|
||||||
const video = document.createElement("video");
|
const video = document.createElement("video");
|
||||||
const player = videojs(video, { qualityLevels: true });
|
const player = videojs(video, {
|
||||||
|
qualityLevels: true,
|
||||||
|
html5: {
|
||||||
|
preloadTextTracks: false,
|
||||||
|
nativeTextTracks: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
// @ts-ignore used for debugging or extending purposes
|
||||||
|
window.videojs = videojs;
|
||||||
|
|
||||||
super(new WebEventEmiter(player));
|
super(new WebEventEmiter(player));
|
||||||
|
|
||||||
@@ -286,6 +294,16 @@ class VideoPlayer extends VideoPlayerEvents implements VideoPlayerBase {
|
|||||||
});
|
});
|
||||||
if (this.mediaSession.enabled)
|
if (this.mediaSession.enabled)
|
||||||
this.mediaSession.updateMediaSession(source.metadata);
|
this.mediaSession.updateMediaSession(source.metadata);
|
||||||
|
|
||||||
|
for (const sub of source.externalSubtitles ?? []) {
|
||||||
|
this.player.addRemoteTextTrack({
|
||||||
|
kind: "subtitles",
|
||||||
|
label: sub.label,
|
||||||
|
src: sub.uri,
|
||||||
|
srclang: sub.language,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (source.initializeOnCreation) await this.preload();
|
if (source.initializeOnCreation) await this.preload();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -308,8 +326,8 @@ class VideoPlayer extends VideoPlayerEvents implements VideoPlayerBase {
|
|||||||
const tracks: VideoJsTextTracks = this.player.textTracks();
|
const tracks: VideoJsTextTracks = this.player.textTracks();
|
||||||
|
|
||||||
for (let i = 0; i < tracks.length; i++) {
|
for (let i = 0; i < tracks.length; i++) {
|
||||||
if (tracks[i]!.mode === "showing") tracks[i]!.mode = "disabled";
|
tracks[i]!.mode =
|
||||||
if (tracks[i]!.id === textTrack?.id) tracks[i]!.mode = "showing";
|
tracks[i]!.id === textTrack?.id ? "showing" : "disabled";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ const VideoView = forwardRef<VideoViewRef, VideoViewProps>(
|
|||||||
ref={vRef}
|
ref={vRef}
|
||||||
style={{
|
style={{
|
||||||
position: "absolute",
|
position: "absolute",
|
||||||
inset: 0
|
inset: 0,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
Reference in New Issue
Block a user