From 9369d65a688e7d1e56f1e798c3d1a7ca2bda20c8 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 17 May 2022 10:55:45 +0530 Subject: [PATCH] Port "Choose best audio quality on streams >= 480p." See https://github.com/TeamPiped/Piped/commit/3dec3744f01745713ca7d45ce26a0537c182ef8f --- src/components/Player.vue | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/components/Player.vue b/src/components/Player.vue index 2bee6b7..f9141f4 100644 --- a/src/components/Player.vue +++ b/src/components/Player.vue @@ -246,16 +246,29 @@ export default { if (qualityConds) { let leastDiff = Number.MAX_VALUE let bestStream = null + + let bestAudio = 0 + // Choose the best audio stream + if (qualityConds >= 480) { + player.getVariantTracks().forEach(track => { + const audioBandwidth = track.audioBandwidth + if (audioBandwidth > bestAudio) bestAudio = audioBandwidth + }) + } + 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) }