From 3dec3744f01745713ca7d45ce26a0537c182ef8f Mon Sep 17 00:00:00 2001 From: Kavin <20838718+FireMasterK@users.noreply.github.com> Date: Sun, 8 May 2022 16:25:20 +0100 Subject: [PATCH] Choose best audio quality on streams >= 480p. Closes #1026 --- src/components/VideoPlayer.vue | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/components/VideoPlayer.vue b/src/components/VideoPlayer.vue index 334933ea..7f1cb7fc 100644 --- a/src/components/VideoPlayer.vue +++ b/src/components/VideoPlayer.vue @@ -485,16 +485,30 @@ export default { if (qualityConds) { var leastDiff = Number.MAX_VALUE; var bestStream = null; + + var bestAudio = 0; + + // Choose the best audio stream + if (qualityConds >= 480) + player.getVariantTracks().forEach(track => { + const audioBandwidth = track.audioBandwidth; + if (audioBandwidth > bestAudio) bestAudio = audioBandwidth; + }); + + // Find best matching stream based on resolution and bitrate player .getVariantTracks() .sort((a, b) => a.bandwidth - b.bandwidth) .forEach(stream => { + if (stream.audioBandwidth < bestAudio) return; + const diff = Math.abs(quality - stream.height); if (diff < leastDiff) { leastDiff = diff; bestStream = stream; } }); + player.selectVariantTrack(bestStream); }