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(() => { player.load(uri, 0, mime).then(() => {
// Set the audio language // 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) { if (qualityConds) {
var leastDiff = Number.MAX_VALUE; var leastDiff = Number.MAX_VALUE;
@ -496,16 +504,19 @@ export default {
var bestAudio = 0; var bestAudio = 0;
const tracks = player
.getVariantTracks()
.filter(track => track.language == lang || track.language == "und");
// Choose the best audio stream // Choose the best audio stream
if (quality >= 480) if (quality >= 480)
player.getVariantTracks().forEach(track => { tracks.forEach(track => {
const audioBandwidth = track.audioBandwidth; const audioBandwidth = track.audioBandwidth;
if (audioBandwidth > bestAudio) bestAudio = audioBandwidth; if (audioBandwidth > bestAudio) bestAudio = audioBandwidth;
}); });
// Find best matching stream based on resolution and bitrate // Find best matching stream based on resolution and bitrate
player tracks
.getVariantTracks()
.sort((a, b) => a.bandwidth - b.bandwidth) .sort((a, b) => a.bandwidth - b.bandwidth)
.forEach(stream => { .forEach(stream => {
if (stream.audioBandwidth < bestAudio) return; if (stream.audioBandwidth < bestAudio) return;