update stream sorting

This commit is contained in:
Luke Pulverenti
2015-03-26 16:31:57 -04:00
parent 8921e152ea
commit 7e312e75bb
13 changed files with 61 additions and 49 deletions

View File

@@ -89,29 +89,7 @@ namespace MediaBrowser.Model.Dlna
private StreamInfo GetOptimalStream(List<StreamInfo> streams)
{
// Grab the first one that can be direct streamed
// If that doesn't produce anything, just take the first
foreach (StreamInfo i in streams)
{
if (i.PlayMethod == PlayMethod.DirectPlay && i.MediaSource.Protocol == MediaProtocol.File)
{
return i;
}
}
foreach (StreamInfo i in streams)
{
if (i.PlayMethod == PlayMethod.DirectPlay)
{
return i;
}
}
foreach (StreamInfo i in streams)
{
if (i.PlayMethod == PlayMethod.DirectStream)
{
return i;
}
}
streams = StreamInfoSorter.SortMediaSources(streams);
foreach (StreamInfo stream in streams)
{

View File

@@ -0,0 +1,40 @@
using MediaBrowser.Model.MediaInfo;
using MediaBrowser.Model.Session;
using System;
using System.Collections.Generic;
using System.Linq;
namespace MediaBrowser.Model.Dlna
{
public class StreamInfoSorter
{
public static List<StreamInfo> SortMediaSources(List<StreamInfo> streams)
{
return streams.OrderBy(i =>
{
switch (i.PlayMethod)
{
case PlayMethod.DirectPlay:
return 0;
case PlayMethod.DirectStream:
return 1;
case PlayMethod.Transcode:
return 2;
default:
throw new ArgumentException("Unrecognized PlayMethod");
}
}).ThenBy(i =>
{
switch (i.MediaSource.Protocol)
{
case MediaProtocol.File:
return 0;
default:
return 1;
}
}).ToList();
}
}
}

View File

@@ -126,6 +126,7 @@
<Compile Include="Devices\DevicesOptions.cs" />
<Compile Include="Dlna\EncodingContext.cs" />
<Compile Include="Dlna\ILocalPlayer.cs" />
<Compile Include="Dlna\StreamInfoSorter.cs" />
<Compile Include="Dlna\NullLocalPlayer.cs" />
<Compile Include="Dlna\PlaybackErrorCode.cs" />
<Compile Include="Dlna\PlaybackException.cs" />