Fix default audio selection ignoring type

This commit is contained in:
Joe Rogers 2022-05-17 21:03:51 +02:00
parent e89d1a3be5
commit 644e774040
No known key found for this signature in database
GPG Key ID: 0074AD57B8FDBBB4
2 changed files with 10 additions and 2 deletions

View File

@ -13,11 +13,11 @@ namespace Emby.Server.Implementations.Library
{ {
public static int? GetDefaultAudioStreamIndex(IReadOnlyList<MediaStream> streams, IReadOnlyList<string> preferredLanguages, bool preferDefaultTrack) public static int? GetDefaultAudioStreamIndex(IReadOnlyList<MediaStream> streams, IReadOnlyList<string> preferredLanguages, bool preferDefaultTrack)
{ {
var sortedStreams = GetSortedStreams(streams, MediaStreamType.Audio, preferredLanguages); var sortedStreams = GetSortedStreams(streams, MediaStreamType.Audio, preferredLanguages).ToList();
if (preferDefaultTrack) if (preferDefaultTrack)
{ {
var defaultStream = streams.FirstOrDefault(i => i.IsDefault); var defaultStream = sortedStreams.FirstOrDefault(i => i.IsDefault);
if (defaultStream != null) if (defaultStream != null)
{ {

View File

@ -27,15 +27,23 @@ public class MediaStreamSelectorTests
{ {
var streams = new MediaStream[] var streams = new MediaStream[]
{ {
new()
{
Index = 0,
Type = MediaStreamType.Video,
IsDefault = true
},
new() new()
{ {
Index = 1, Index = 1,
Type = MediaStreamType.Audio,
Language = "fre", Language = "fre",
IsDefault = true IsDefault = true
}, },
new() new()
{ {
Index = 2, Index = 2,
Type = MediaStreamType.Audio,
Language = "eng", Language = "eng",
IsDefault = false IsDefault = false
} }