From 72023207a43d66035d8868f986ceabdc8f1912f4 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 2 Apr 2015 12:24:59 -0400 Subject: [PATCH] fix hasMediaSources exception --- .../Session/SessionManager.cs | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/MediaBrowser.Server.Implementations/Session/SessionManager.cs b/MediaBrowser.Server.Implementations/Session/SessionManager.cs index cc5aef54a..7f5033b98 100644 --- a/MediaBrowser.Server.Implementations/Session/SessionManager.cs +++ b/MediaBrowser.Server.Implementations/Session/SessionManager.cs @@ -305,7 +305,7 @@ namespace MediaBrowser.Server.Implementations.Session } } - private async Task GetMediaSource(BaseItem item, string mediaSourceId) + private async Task GetMediaSource(IHasMediaSources item, string mediaSourceId) { var sources = await _mediaSourceManager.GetPlayackMediaSources(item.Id.ToString("N"), false, CancellationToken.None) .ConfigureAwait(false); @@ -334,11 +334,16 @@ namespace MediaBrowser.Server.Implementations.Session { var runtimeTicks = libraryItem.RunTimeTicks; - var mediaSource = await GetMediaSource(libraryItem, info.MediaSourceId).ConfigureAwait(false); - - if (mediaSource != null) + MediaSourceInfo mediaSource = null; + var hasMediaSources = libraryItem as IHasMediaSources; + if (hasMediaSources != null) { - runtimeTicks = mediaSource.RunTimeTicks; + mediaSource = await GetMediaSource(hasMediaSources, info.MediaSourceId).ConfigureAwait(false); + + if (mediaSource != null) + { + runtimeTicks = mediaSource.RunTimeTicks; + } } info.Item = GetItemInfo(libraryItem, libraryItem, mediaSource); @@ -414,12 +419,12 @@ namespace MediaBrowser.Server.Implementations.Session if (!_activeConnections.TryGetValue(key, out sessionInfo)) { sessionInfo = new SessionInfo - { - Client = appName, - DeviceId = deviceId, - ApplicationVersion = appVersion, - Id = key.GetMD5().ToString("N") - }; + { + Client = appName, + DeviceId = deviceId, + ApplicationVersion = appVersion, + Id = key.GetMD5().ToString("N") + }; sessionInfo.DeviceName = deviceName; sessionInfo.UserId = userId; @@ -756,7 +761,13 @@ namespace MediaBrowser.Server.Implementations.Session if (current == null || !string.Equals(current.Id, info.ItemId, StringComparison.OrdinalIgnoreCase)) { - var mediaSource = await GetMediaSource(libraryItem, info.MediaSourceId).ConfigureAwait(false); + MediaSourceInfo mediaSource = null; + + var hasMediaSources = libraryItem as IHasMediaSources; + if (hasMediaSources != null) + { + mediaSource = await GetMediaSource(hasMediaSources, info.MediaSourceId).ConfigureAwait(false); + } info.Item = GetItemInfo(libraryItem, libraryItem, mediaSource); }