Update base.ts

This commit is contained in:
Pas 2026-01-18 14:22:33 -07:00
parent 93b5971f1f
commit 215cf9e367

View file

@ -170,12 +170,9 @@ export function makeVideoElementDisplayInterface(): DisplayInterface {
hls.currentLevel = -1; hls.currentLevel = -1;
hls.loadLevel = -1; hls.loadLevel = -1;
} }
// Only emit quality when we have a valid level index (>= 0) // For manual quality selection, wait for LEVEL_SWITCHED to emit quality
// When automaticQuality is true, currentLevel is -1, so we wait for LEVEL_SWITCHED event // to avoid showing intermediate states when HLS switches away from unplayable levels
if (hls.currentLevel >= 0) { // For automatic quality, currentLevel is -1, so we wait for LEVEL_SWITCHED event
const quality = hlsLevelToQuality(hls.levels[hls.currentLevel]);
emit("changedquality", quality);
}
} }
function setupSource(vid: HTMLVideoElement, src: LoadableSource) { function setupSource(vid: HTMLVideoElement, src: LoadableSource) {
@ -313,29 +310,16 @@ export function makeVideoElementDisplayInterface(): DisplayInterface {
// Don't process level switched events during debounced quality changes // Don't process level switched events during debounced quality changes
if (qualityChangeTimeout) return; if (qualityChangeTimeout) return;
const currentLevel = hls.levels[hls.currentLevel];
const currentQuality = hlsLevelToQuality(currentLevel);
if (automaticQuality) { if (automaticQuality) {
// Only emit quality changes when automatic quality is enabled // Only emit quality changes when automatic quality is enabled
const quality = hlsLevelToQuality(hls.levels[hls.currentLevel]); emit("changedquality", currentQuality);
emit("changedquality", quality);
} else { } else {
// When automatic quality is disabled, check if current level matches preferred quality // For manual quality selection, emit the user's preferred quality
const currentQuality = hlsLevelToQuality( // This ensures the UI shows the selected quality, not the actual playing quality
hls.levels[hls.currentLevel], emit("changedquality", preferenceQuality);
);
const preferredQualityLevel = getPreferredQuality(
hlsLevelsToQualities(hls.levels),
{
lastChosenQuality: preferenceQuality,
automaticQuality: false,
},
);
// Only re-lock if the current level doesn't match our preferred quality
if (currentQuality !== preferredQualityLevel) {
setupQualityForHls();
} else {
// Emit the quality change since we're now at the correct level
emit("changedquality", currentQuality);
}
} }
}); });
hls.on(Hls.Events.SUBTITLE_TRACK_LOADED, () => { hls.on(Hls.Events.SUBTITLE_TRACK_LOADED, () => {