Backport pull request #4263 from jellyfin/release-10.8.z

Fix change audio track

Original-merge: 9139153d16e39c40d068435fe642925a2d7a66a3

Merged-by: Bill Thornton <thornbill@users.noreply.github.com>

Backported-by: Joshua M. Boniface <joshua@boniface.me>
This commit is contained in:
Dmitry Lyzo 2023-01-22 14:08:02 -05:00 committed by Joshua M. Boniface
parent 5e6de2d7db
commit abed235b50
4 changed files with 84 additions and 42 deletions

View file

@ -27,10 +27,11 @@ import itemHelper from '../../components/itemHelper';
import Screenfull from 'screenfull';
import globalize from '../../scripts/globalize';
import ServerConnections from '../../components/ServerConnections';
import profileBuilder from '../../scripts/browserDeviceProfile';
import profileBuilder, { canPlaySecondaryAudio } from '../../scripts/browserDeviceProfile';
import { getIncludeCorsCredentials } from '../../scripts/settings/webSettings';
import { setBackdropTransparency, TRANSPARENCY_LEVEL } from '../../components/backdrop/backdrop';
import Events from '../../utils/events.ts';
import { includesAny } from '../../utils/container.ts';
/**
* Returns resolved URL.
@ -593,7 +594,7 @@ function tryRemoveElement(elem) {
/**
* @private
*/
isAudioStreamSupported(stream, deviceProfile) {
isAudioStreamSupported(stream, deviceProfile, container) {
const codec = (stream.Codec || '').toLowerCase();
if (!codec) {
@ -607,17 +608,11 @@ function tryRemoveElement(elem) {
const profiles = deviceProfile.DirectPlayProfiles || [];
return profiles.filter(function (p) {
if (p.Type === 'Video') {
if (!p.AudioCodec) {
return true;
}
return p.AudioCodec.toLowerCase().includes(codec);
}
return false;
}).length > 0;
return profiles.some(function (p) {
return p.Type === 'Video'
&& includesAny((p.Container || '').toLowerCase(), container)
&& includesAny((p.AudioCodec || '').toLowerCase(), codec);
});
}
/**
@ -626,8 +621,11 @@ function tryRemoveElement(elem) {
getSupportedAudioStreams() {
const profile = this.#lastProfile;
return getMediaStreamAudioTracks(this._currentPlayOptions.mediaSource).filter((stream) => {
return this.isAudioStreamSupported(stream, profile);
const mediaSource = this._currentPlayOptions.mediaSource;
const container = mediaSource.Container.toLowerCase();
return getMediaStreamAudioTracks(mediaSource).filter((stream) => {
return this.isAudioStreamSupported(stream, profile, container);
});
}
@ -1545,12 +1543,12 @@ function tryRemoveElement(elem) {
}
canSetAudioStreamIndex() {
if (browser.tizen || browser.orsay) {
return true;
const video = this.#mediaElement;
if (video) {
return canPlaySecondaryAudio(video);
}
const video = this.#mediaElement;
return !!video?.audioTracks;
return false;
}
static onPictureInPictureError(err) {