Skip to content

Commit

Permalink
fix(player): save captions hidden in local storage (#1235)
Browse files Browse the repository at this point in the history
closes #1234
  • Loading branch information
PJUllrich authored Apr 7, 2024
1 parent 287d1f8 commit c191ee0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/vidstack/mangle.json
Original file line number Diff line number Diff line change
Expand Up @@ -866,5 +866,6 @@
"_parseContent": "ap",
"_onEndPrecisionChange": "fp",
"_setAudioGain": "gp",
"_updateColorScheme": "hp"
"_updateColorScheme": "hp",
"_pendingRemoval": "ip"
}
10 changes: 8 additions & 2 deletions packages/vidstack/src/core/tracks/text/text-tracks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,14 @@ export class TextTrackList extends List<TextTrack, TextTrackListEvents> {
}

remove(track: TextTrack, trigger?: Event) {
this._pendingRemoval = track;
if (!this._items.includes(track)) return;
if (track === this._defaults[track.kind]) delete this._defaults[track.kind];
track.mode = 'disabled';
track[TextTrackSymbol._onModeChange] = null;
track.removeEventListener('mode-change', this._onTrackModeChangeBind);
this[ListSymbol._remove](track, trigger);
this._pendingRemoval = null;
return this;
}

Expand Down Expand Up @@ -136,11 +138,13 @@ export class TextTrackList extends List<TextTrack, TextTrackListEvents> {
}
}, 300);

private _pendingRemoval: TextTrack | null = null;
private _onTrackModeChangeBind = this._onTrackModeChange.bind(this);
private _onTrackModeChange(event: TextTrackModeChangeEvent) {
const track = event.detail;

if (this._storage && isTrackCaptionKind(track) && track.mode !== 'disabled') {
// We need to check whether track is being removed to not mistakenly save "disabled" mode change.
if (this._storage && isTrackCaptionKind(track) && track !== this._pendingRemoval) {
this._saveCaptionsTrack(track);
}

Expand All @@ -162,7 +166,9 @@ export class TextTrackList extends List<TextTrack, TextTrackListEvents> {
}

private _saveCaptionsTrack(track: TextTrack) {
this._saveLang(track.language);
if (track.mode !== 'disabled') {
this._saveLang(track.language);
}
this._storage?.setCaptions?.(track.mode === 'showing');
}

Expand Down

0 comments on commit c191ee0

Please sign in to comment.