Fix MediaStreamSelector

This commit is contained in:
Bond_009 2022-02-14 15:03:08 +01:00
parent 8b2556adba
commit dbd7be091d
2 changed files with 36 additions and 1 deletions

View File

@ -17,7 +17,12 @@ namespace Emby.Server.Implementations.Library
if (preferDefaultTrack)
{
return sortedStreams.FirstOrDefault(i => i.IsDefault)?.Index;
var defaultStream = streams.FirstOrDefault(i => i.IsDefault);
if (defaultStream != null)
{
return defaultStream.Index;
}
}
return sortedStreams.FirstOrDefault()?.Index;

View File

@ -0,0 +1,30 @@
using System;
using Emby.Server.Implementations.Library;
using MediaBrowser.Model.Entities;
using Xunit;
namespace Jellyfin.Server.Implementations.Tests.Library;
public class MediaStreamSelectorTests
{
[Theory]
[InlineData(true)]
[InlineData(false)]
public void GetDefaultAudioStreamIndex_EmptyStreams_Null(bool preferDefaultTrack)
{
Assert.Null(MediaStreamSelector.GetDefaultAudioStreamIndex(Array.Empty<MediaStream>(), Array.Empty<string>(), preferDefaultTrack));
}
[Theory]
[InlineData(true)]
[InlineData(false)]
public void GetDefaultAudioStreamIndex_WithoutDefault_NotNull(bool preferDefaultTrack)
{
var streams = new[]
{
new MediaStream()
};
Assert.NotNull(MediaStreamSelector.GetDefaultAudioStreamIndex(streams, Array.Empty<string>(), preferDefaultTrack));
}
}