Port "Choose best audio quality on streams >= 480p."

See https://github.com/TeamPiped/Piped/commit/3dec3744f01745713ca7d45ce26a0537c182ef8f
This commit is contained in:
root
2022-05-17 10:55:45 +05:30
parent a16a66cc27
commit 9369d65a68
+13
View File
@@ -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)
}