From 5d66c84f2d34aca4db2e27419088ad95fb7c5807 Mon Sep 17 00:00:00 2001 From: Joe Rogers <1337joe@gmail.com> Date: Tue, 17 May 2022 21:03:51 +0200 Subject: [PATCH] Fix default audio selection ignoring type --- .../Library/MediaStreamSelector.cs | 4 ++-- .../Library/MediaStreamSelectorTests.cs | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Emby.Server.Implementations/Library/MediaStreamSelector.cs b/Emby.Server.Implementations/Library/MediaStreamSelector.cs index c5abb9a0a3..20a2edb05a 100644 --- a/Emby.Server.Implementations/Library/MediaStreamSelector.cs +++ b/Emby.Server.Implementations/Library/MediaStreamSelector.cs @@ -13,11 +13,11 @@ namespace Emby.Server.Implementations.Library { public static int? GetDefaultAudioStreamIndex(IReadOnlyList streams, IReadOnlyList preferredLanguages, bool preferDefaultTrack) { - var sortedStreams = GetSortedStreams(streams, MediaStreamType.Audio, preferredLanguages); + var sortedStreams = GetSortedStreams(streams, MediaStreamType.Audio, preferredLanguages).ToList(); if (preferDefaultTrack) { - var defaultStream = streams.FirstOrDefault(i => i.IsDefault); + var defaultStream = sortedStreams.FirstOrDefault(i => i.IsDefault); if (defaultStream != null) { diff --git a/tests/Jellyfin.Server.Implementations.Tests/Library/MediaStreamSelectorTests.cs b/tests/Jellyfin.Server.Implementations.Tests/Library/MediaStreamSelectorTests.cs index 2b1c6e937b..538010f6c0 100644 --- a/tests/Jellyfin.Server.Implementations.Tests/Library/MediaStreamSelectorTests.cs +++ b/tests/Jellyfin.Server.Implementations.Tests/Library/MediaStreamSelectorTests.cs @@ -27,15 +27,23 @@ public class MediaStreamSelectorTests { var streams = new MediaStream[] { + new() + { + Index = 0, + Type = MediaStreamType.Video, + IsDefault = true + }, new() { Index = 1, + Type = MediaStreamType.Audio, Language = "fre", IsDefault = true }, new() { Index = 2, + Type = MediaStreamType.Audio, Language = "eng", IsDefault = false }