mirror of
https://github.com/zoriya/react-native-video.git
synced 2025-12-06 07:16:12 +00:00
Handle text track change event
This commit is contained in:
@@ -80,6 +80,9 @@ export class WebEventEmiter implements PlayerEvents {
|
|||||||
this._onError = this._onError.bind(this);
|
this._onError = this._onError.bind(this);
|
||||||
this.player.on("error", this._onError);
|
this.player.on("error", this._onError);
|
||||||
|
|
||||||
|
this._onTextTrackChange = this._onTextTrackChange.bind(this);
|
||||||
|
this.player.textTracks().on("change", this._onTextTrackChange);
|
||||||
|
|
||||||
this._onAudioTrackChange = this._onAudioTrackChange.bind(this);
|
this._onAudioTrackChange = this._onAudioTrackChange.bind(this);
|
||||||
this.player.audioTracks().on("change", this._onAudioTrackChange);
|
this.player.audioTracks().on("change", this._onAudioTrackChange);
|
||||||
|
|
||||||
@@ -114,6 +117,8 @@ export class WebEventEmiter implements PlayerEvents {
|
|||||||
|
|
||||||
this.player.off("error", this._onError);
|
this.player.off("error", this._onError);
|
||||||
|
|
||||||
|
this.player.textTracks().off("change", this._onTextTrackChange);
|
||||||
|
|
||||||
this.player.audioTracks().off("change", this._onAudioTrackChange);
|
this.player.audioTracks().off("change", this._onAudioTrackChange);
|
||||||
|
|
||||||
this.player.videoTracks().off("change", this._onVideoTrackChange);
|
this.player.videoTracks().off("change", this._onVideoTrackChange);
|
||||||
@@ -238,6 +243,21 @@ export class WebEventEmiter implements PlayerEvents {
|
|||||||
this.onError(new VideoError(codeMap[err.code]!, err.message));
|
this.onError(new VideoError(codeMap[err.code]!, err.message));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_onTextTrackChange() {
|
||||||
|
// @ts-expect-error they define length & index properties via prototype
|
||||||
|
const tracks: VideoJsTextTracks = this.player.textTracks();
|
||||||
|
const selected = [...Array(tracks.length)]
|
||||||
|
.map((_, i) => ({
|
||||||
|
id: tracks[i]!.id,
|
||||||
|
label: tracks[i]!.label,
|
||||||
|
language: tracks[i]!.language,
|
||||||
|
selected: tracks[i]!.mode === "showing",
|
||||||
|
}))
|
||||||
|
.find((x) => x.selected);
|
||||||
|
|
||||||
|
this.onTrackChange(selected ?? null);
|
||||||
|
}
|
||||||
|
|
||||||
_onAudioTrackChange() {
|
_onAudioTrackChange() {
|
||||||
// @ts-expect-error they define length & index properties via prototype
|
// @ts-expect-error they define length & index properties via prototype
|
||||||
const tracks: VideoJsTracks = this.player.audioTracks();
|
const tracks: VideoJsTracks = this.player.audioTracks();
|
||||||
|
|||||||
Reference in New Issue
Block a user