Filter audio tracks in variants too.

This commit is contained in:
Kavin 2022-11-15 21:16:19 +00:00
parent 5a268b26bd
commit 455edfcf7c
No known key found for this signature in database
GPG key ID: 49451E4482CC5BCD

View file

@ -488,7 +488,15 @@ export default {
player.load(uri, 0, mime).then(() => {
// Set the audio language
player.selectAudioLanguage(this.getPreferenceString("hl", "en").substr(0, 2));
const prefLang = this.getPreferenceString("hl", "en").substr(0, 2);
var lang = "en";
for (var l in player.getAudioLanguages()) {
if (l == prefLang) {
lang = l;
return;
}
}
player.selectAudioLanguage(lang);
if (qualityConds) {
var leastDiff = Number.MAX_VALUE;
@ -496,16 +504,19 @@ export default {
var bestAudio = 0;
const tracks = player
.getVariantTracks()
.filter(track => track.language == lang || track.language == "und");
// Choose the best audio stream
if (quality >= 480)
player.getVariantTracks().forEach(track => {
tracks.forEach(track => {
const audioBandwidth = track.audioBandwidth;
if (audioBandwidth > bestAudio) bestAudio = audioBandwidth;
});
// Find best matching stream based on resolution and bitrate
player
.getVariantTracks()
tracks
.sort((a, b) => a.bandwidth - b.bandwidth)
.forEach(stream => {
if (stream.audioBandwidth < bestAudio) return;