aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations/Session/SessionManager.cs
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2015-03-29 12:45:16 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2015-03-29 12:45:16 -0400
commita79962b7ebfe59d837970581ac1b5f184b0aa42d (patch)
tree44c5115926bd356cd844e09ef55481b486c9343d /MediaBrowser.Server.Implementations/Session/SessionManager.cs
parent87bf3bbb8fca91d254b5e9eab4a143cf96af4cac (diff)
update live stream generation
Diffstat (limited to 'MediaBrowser.Server.Implementations/Session/SessionManager.cs')
-rw-r--r--MediaBrowser.Server.Implementations/Session/SessionManager.cs57
1 files changed, 36 insertions, 21 deletions
diff --git a/MediaBrowser.Server.Implementations/Session/SessionManager.cs b/MediaBrowser.Server.Implementations/Session/SessionManager.cs
index ec93ae876..16fc42063 100644
--- a/MediaBrowser.Server.Implementations/Session/SessionManager.cs
+++ b/MediaBrowser.Server.Implementations/Session/SessionManager.cs
@@ -14,6 +14,7 @@ using MediaBrowser.Controller.Persistence;
using MediaBrowser.Controller.Security;
using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Devices;
+using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Events;
using MediaBrowser.Model.Library;
@@ -304,13 +305,21 @@ namespace MediaBrowser.Server.Implementations.Session
}
}
+ private async Task<MediaSourceInfo> GetMediaSource(BaseItem item, string mediaSourceId)
+ {
+ var sources = await _mediaSourceManager.GetPlayackMediaSources(item.Id.ToString("N"), false, CancellationToken.None)
+ .ConfigureAwait(false);
+
+ return sources.FirstOrDefault(i => string.Equals(i.Id, mediaSourceId, StringComparison.OrdinalIgnoreCase));
+ }
+
/// <summary>
/// Updates the now playing item id.
/// </summary>
/// <param name="session">The session.</param>
/// <param name="info">The information.</param>
/// <param name="libraryItem">The library item.</param>
- private void UpdateNowPlayingItem(SessionInfo session, PlaybackProgressInfo info, BaseItem libraryItem)
+ private async Task UpdateNowPlayingItem(SessionInfo session, PlaybackProgressInfo info, BaseItem libraryItem)
{
if (string.IsNullOrWhiteSpace(info.MediaSourceId))
{
@@ -319,29 +328,27 @@ namespace MediaBrowser.Server.Implementations.Session
if (!string.IsNullOrWhiteSpace(info.ItemId) && info.Item == null && libraryItem != null)
{
- var runtimeTicks = libraryItem.RunTimeTicks;
+ var current = session.NowPlayingItem;
- if (!string.Equals(info.ItemId, info.MediaSourceId) &&
- !string.IsNullOrWhiteSpace(info.MediaSourceId))
+ if (current == null || !string.Equals(current.Id, info.ItemId, StringComparison.OrdinalIgnoreCase))
{
- var runtimeItem = _libraryManager.GetItemById(new Guid(info.MediaSourceId)) ??
- _libraryManager.GetItemById(info.ItemId);
+ var runtimeTicks = libraryItem.RunTimeTicks;
- runtimeTicks = runtimeItem.RunTimeTicks;
- }
+ var mediaSource = await GetMediaSource(libraryItem, info.MediaSourceId).ConfigureAwait(false);
- var current = session.NowPlayingItem;
+ if (mediaSource != null)
+ {
+ runtimeTicks = mediaSource.RunTimeTicks;
+ }
- if (current == null || !string.Equals(current.Id, info.ItemId, StringComparison.OrdinalIgnoreCase))
- {
- info.Item = GetItemInfo(libraryItem, libraryItem, info.MediaSourceId);
+ info.Item = GetItemInfo(libraryItem, libraryItem, mediaSource);
+
+ info.Item.RunTimeTicks = runtimeTicks;
}
else
{
info.Item = current;
}
-
- info.Item.RunTimeTicks = runtimeTicks;
}
session.NowPlayingItem = info.Item;
@@ -432,6 +439,12 @@ namespace MediaBrowser.Server.Implementations.Session
device = device ?? _deviceManager.GetDevice(deviceId);
+ if (device == null)
+ {
+ var userIdString = userId.HasValue ? userId.Value.ToString("N") : null;
+ device = await _deviceManager.RegisterDevice(deviceId, deviceName, appName, appVersion, userIdString).ConfigureAwait(false);
+ }
+
if (device != null)
{
if (!string.IsNullOrEmpty(device.CustomName))
@@ -570,7 +583,7 @@ namespace MediaBrowser.Server.Implementations.Session
? null
: _libraryManager.GetItemById(new Guid(info.ItemId));
- UpdateNowPlayingItem(session, info, libraryItem);
+ await UpdateNowPlayingItem(session, info, libraryItem).ConfigureAwait(false);
if (!string.IsNullOrEmpty(session.DeviceId) && info.PlayMethod != PlayMethod.Transcode)
{
@@ -652,7 +665,7 @@ namespace MediaBrowser.Server.Implementations.Session
? null
: _libraryManager.GetItemById(new Guid(info.ItemId));
- UpdateNowPlayingItem(session, info, libraryItem);
+ await UpdateNowPlayingItem(session, info, libraryItem).ConfigureAwait(false);
var users = GetUsers(session);
@@ -731,7 +744,9 @@ namespace MediaBrowser.Server.Implementations.Session
if (current == null || !string.Equals(current.Id, info.ItemId, StringComparison.OrdinalIgnoreCase))
{
- info.Item = GetItemInfo(libraryItem, libraryItem, info.MediaSourceId);
+ var mediaSource = await GetMediaSource(libraryItem, info.MediaSourceId).ConfigureAwait(false);
+
+ info.Item = GetItemInfo(libraryItem, libraryItem, mediaSource);
}
else
{
@@ -1439,10 +1454,10 @@ namespace MediaBrowser.Server.Implementations.Session
/// </summary>
/// <param name="item">The item.</param>
/// <param name="chapterOwner">The chapter owner.</param>
- /// <param name="mediaSourceId">The media source identifier.</param>
+ /// <param name="mediaSource">The media source.</param>
/// <returns>BaseItemInfo.</returns>
/// <exception cref="System.ArgumentNullException">item</exception>
- private BaseItemInfo GetItemInfo(BaseItem item, BaseItem chapterOwner, string mediaSourceId)
+ private BaseItemInfo GetItemInfo(BaseItem item, BaseItem chapterOwner, MediaSourceInfo mediaSource)
{
if (item == null)
{
@@ -1593,9 +1608,9 @@ namespace MediaBrowser.Server.Implementations.Session
info.Chapters = _dtoService.GetChapterInfoDtos(chapterOwner).ToList();
}
- if (!string.IsNullOrWhiteSpace(mediaSourceId))
+ if (mediaSource != null)
{
- info.MediaStreams = _mediaSourceManager.GetMediaStreams(mediaSourceId).ToList();
+ info.MediaStreams = mediaSource.MediaStreams;
}
return info;