Recover Chromium HLS audio at ad discontinuities

This commit is contained in:
Technomancer702
2026-10-13 17:23:00 -07:00
parent 035667cfba
commit b9dad30f06
14 changed files with 454 additions and 216 deletions

View File

@ -9,6 +9,7 @@ class CaptionTracks {
this.hlsTracks = new Map();
this.retired = new Set();
this.generation = 0;
this.selectionRevision = 0;
this.video.textTracks?.addEventListener('change', onChange);
this.video.textTracks?.addEventListener('addtrack', onChange);
this.video.textTracks?.addEventListener('removetrack', onChange);
@ -55,6 +56,20 @@ class CaptionTracks {
this.probe = { subtitles: info?.subtitles || [], url };
}
prepareMediaRecovery() {
if (!this.remoteTracks.length) return;
const selected = this.remoteTracks.findIndex(element => element.track.mode === 'showing');
const generation = this.generation, revision = this.selectionRevision;
return () => {
if (this.generation !== generation || this.selectionRevision !== revision) return;
// HLS detachment clears native cues, including extracted remote subtitles.
this.removeRemoteTracks();
this.addRemoteTracks();
if (selected >= 0 && this.remoteTracks[selected]) this.remoteTracks[selected].track.mode = 'showing';
this.onChange();
};
}
useNative({ allowProbe = true } = {}) {
this.generation++;
this.hls = null;
@ -203,6 +218,7 @@ class CaptionTracks {
active: hls.subtitleDisplay !== false && hls.subtitleTrack === index,
select: () => {
if (this.hls !== hls || hls.subtitleTracks[index] !== track) return;
this.selectionRevision++;
this.disableNativeTracks();
hls.subtitleDisplay = true;
hls.subtitleTrack = index;
@ -238,6 +254,7 @@ class CaptionTracks {
}
off() {
this.selectionRevision++;
if (this.hls) {
this.hls.subtitleTrack = -1;
this.hls.subtitleDisplay = false;