Skip to content

Commit

Permalink
fix(SUP-42730): Captions not showing after enabling (#219)
Browse files Browse the repository at this point in the history
Issue:
When play the video with caption disabled, caption is not shown after enable the caption (when the caption is default)

Fix:
Listen to SUBTITLE_FRAG_PROCESSED (hls event) that's triggered after the captions request and parsing then hide the captions from our side.

Resolves SUP-42730
  • Loading branch information
Tzipi-kaltura authored Jun 4, 2024
1 parent cbcaa71 commit d080c4f
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/hls-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export default class HlsAdapter extends BaseMediaSourceAdapter {
private _nativeTextTracksMap: any = {};
private _lastLoadedFragSN: number = -1;
private _sameFragSNLoadedCount: number = 0;
private _waitForSubtitleLoad: boolean = true;
/**
* an object containing all the events we bind and unbind to.
* @member {Object} - _adapterEventsBindings
Expand Down Expand Up @@ -791,18 +792,27 @@ export default class HlsAdapter extends BaseMediaSourceAdapter {
this._onTrackChanged(textTrack);
}

private _onSubtitleFragProcessed(): void {
this._hls.subtitleTrack = -1;
this._waitForSubtitleLoad = false;
this._hls.off(Hlsjs.Events.SUBTITLE_FRAG_PROCESSED, this._onSubtitleFragProcessed, this._hls);
}

/** Hide the text track
* @function hideTextTrack
* @returns {void}
* @public
*/
public hideTextTrack(): void {
if (this._hls) {
if (this._hls.subtitleTracks.length) {
this._hls.subtitleTrack = -1;
} else {
this.disableNativeTextTracks();
}
if (!this._hls){
return;
}
if (!this._hls.subtitleTracks.length) {
this.disableNativeTextTracks();
} else if (this._waitForSubtitleLoad){
this._hls.on(Hlsjs.Events.SUBTITLE_FRAG_PROCESSED, this. _onSubtitleFragProcessed, this._hls)
} else {
this._hls.subtitleTrack = -1;
}
}

Expand Down Expand Up @@ -1244,6 +1254,7 @@ export default class HlsAdapter extends BaseMediaSourceAdapter {
for (const [event, callback] of Object.entries<(...parms: any) => any>(this._adapterEventsBindings)) {
this._hls.off(event as keyof HlsListeners, callback);
}
this._hls.off(Hlsjs.Events.SUBTITLE_FRAG_PROCESSED, this._onSubtitleFragProcessed, this._hls);
this._videoElement.textTracks.onaddtrack = null;
this._onRecoveredCallback = null;
if (this._eventManager) {
Expand Down

0 comments on commit d080c4f

Please sign in to comment.