made session a little more flexible for playing non-library items

This commit is contained in:
Luke Pulverenti 2013-09-30 11:05:07 -04:00
parent f4f91a8316
commit 29fd559f0a
7 changed files with 132 additions and 44 deletions

View File

@ -697,7 +697,16 @@ namespace MediaBrowser.Api.UserLibrary
var item = _dtoService.GetItemByDtoId(request.Id, user.Id);
var task = _sessionManager.OnPlaybackProgress(item, request.PositionTicks, request.IsPaused, request.IsMuted, GetSession().Id);
var info = new PlaybackProgressInfo
{
Item = item,
PositionTicks = request.PositionTicks,
IsMuted = request.IsMuted,
IsPaused = request.IsPaused,
SessionId = GetSession().Id
};
var task = _sessionManager.OnPlaybackProgress(info);
Task.WaitAll(task);
}
@ -717,7 +726,14 @@ namespace MediaBrowser.Api.UserLibrary
var session = GetSession();
var task = _sessionManager.OnPlaybackStopped(item, request.PositionTicks, session.Id);
var info = new PlaybackStopInfo
{
Item = item,
PositionTicks = request.PositionTicks,
SessionId = session.Id
};
var task = _sessionManager.OnPlaybackStopped(info);
Task.WaitAll(task);
}

View File

@ -175,6 +175,8 @@
<Compile Include="Providers\BaseMetadataProvider.cs" />
<Compile Include="Session\ISessionRemoteController.cs" />
<Compile Include="Session\PlaybackInfo.cs" />
<Compile Include="Session\PlaybackProgressInfo.cs" />
<Compile Include="Session\PlaybackStopInfo.cs" />
<Compile Include="Session\SessionInfo.cs" />
<Compile Include="Sorting\IBaseItemComparer.cs" />
<Compile Include="Sorting\IUserBaseItemComparer.cs" />

View File

@ -62,24 +62,18 @@ namespace MediaBrowser.Controller.Session
/// <summary>
/// Used to report playback progress for an item
/// </summary>
/// <param name="item">The item.</param>
/// <param name="positionTicks">The position ticks.</param>
/// <param name="isPaused">if set to <c>true</c> [is paused].</param>
/// <param name="isMuted">if set to <c>true</c> [is muted].</param>
/// <param name="sessionId">The session id.</param>
/// <param name="info">The info.</param>
/// <returns>Task.</returns>
/// <exception cref="System.ArgumentNullException"></exception>
Task OnPlaybackProgress(BaseItem item, long? positionTicks, bool isPaused, bool isMuted, Guid sessionId);
Task OnPlaybackProgress(PlaybackProgressInfo info);
/// <summary>
/// Used to report that playback has ended for an item
/// </summary>
/// <param name="item">The item.</param>
/// <param name="positionTicks">The position ticks.</param>
/// <param name="sessionId">The session id.</param>
/// <param name="info">The info.</param>
/// <returns>Task.</returns>
/// <exception cref="System.ArgumentNullException"></exception>
Task OnPlaybackStopped(BaseItem item, long? positionTicks, Guid sessionId);
Task OnPlaybackStopped(PlaybackStopInfo info);
/// <summary>
/// Sends the system command.

View File

@ -0,0 +1,38 @@
using MediaBrowser.Controller.Entities;
using System;
namespace MediaBrowser.Controller.Session
{
public class PlaybackProgressInfo
{
/// <summary>
/// Gets or sets the item.
/// </summary>
/// <value>The item.</value>
public BaseItem Item { get; set; }
/// <summary>
/// Gets or sets the session id.
/// </summary>
/// <value>The session id.</value>
public Guid SessionId { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this instance is paused.
/// </summary>
/// <value><c>true</c> if this instance is paused; otherwise, <c>false</c>.</value>
public bool IsPaused { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this instance is muted.
/// </summary>
/// <value><c>true</c> if this instance is muted; otherwise, <c>false</c>.</value>
public bool IsMuted { get; set; }
/// <summary>
/// Gets or sets the position ticks.
/// </summary>
/// <value>The position ticks.</value>
public long? PositionTicks { get; set; }
}
}

View File

@ -0,0 +1,26 @@
using MediaBrowser.Controller.Entities;
using System;
namespace MediaBrowser.Controller.Session
{
public class PlaybackStopInfo
{
/// <summary>
/// Gets or sets the item.
/// </summary>
/// <value>The item.</value>
public BaseItem Item { get; set; }
/// <summary>
/// Gets or sets the session id.
/// </summary>
/// <value>The session id.</value>
public Guid SessionId { get; set; }
/// <summary>
/// Gets or sets the position ticks.
/// </summary>
/// <value>The position ticks.</value>
public long? PositionTicks { get; set; }
}
}

View File

@ -266,46 +266,43 @@ namespace MediaBrowser.Server.Implementations.Session
/// <summary>
/// Used to report playback progress for an item
/// </summary>
/// <param name="item">The item.</param>
/// <param name="positionTicks">The position ticks.</param>
/// <param name="isPaused">if set to <c>true</c> [is paused].</param>
/// <param name="sessionId">The session id.</param>
/// <param name="info">The info.</param>
/// <returns>Task.</returns>
/// <exception cref="System.ArgumentNullException"></exception>
/// <exception cref="System.ArgumentOutOfRangeException">positionTicks</exception>
public async Task OnPlaybackProgress(BaseItem item, long? positionTicks, bool isPaused, bool isMuted, Guid sessionId)
public async Task OnPlaybackProgress(PlaybackProgressInfo info)
{
if (item == null)
if (info == null)
{
throw new ArgumentNullException();
throw new ArgumentNullException("info");
}
if (positionTicks.HasValue && positionTicks.Value < 0)
if (info.PositionTicks.HasValue && info.PositionTicks.Value < 0)
{
throw new ArgumentOutOfRangeException("positionTicks");
}
var session = Sessions.First(i => i.Id.Equals(sessionId));
var session = Sessions.First(i => i.Id.Equals(info.SessionId));
UpdateNowPlayingItem(session, item, isPaused, isMuted, positionTicks);
UpdateNowPlayingItem(session, info.Item, info.IsPaused, info.IsMuted, info.PositionTicks);
var key = item.GetUserDataKey();
var key = info.Item.GetUserDataKey();
var user = session.User;
if (positionTicks.HasValue)
if (info.PositionTicks.HasValue)
{
var data = _userDataRepository.GetUserData(user.Id, key);
UpdatePlayState(item, data, positionTicks.Value);
UpdatePlayState(info.Item, data, info.PositionTicks.Value);
await _userDataRepository.SaveUserData(user.Id, key, data, CancellationToken.None).ConfigureAwait(false);
}
EventHelper.QueueEventIfNotNull(PlaybackProgress, this, new PlaybackProgressEventArgs
{
Item = item,
Item = info.Item,
User = user,
PlaybackPositionTicks = positionTicks
PlaybackPositionTicks = info.PositionTicks
}, _logger);
}
@ -313,36 +310,35 @@ namespace MediaBrowser.Server.Implementations.Session
/// <summary>
/// Used to report that playback has ended for an item
/// </summary>
/// <param name="item">The item.</param>
/// <param name="positionTicks">The position ticks.</param>
/// <param name="sessionId">The session id.</param>
/// <param name="info">The info.</param>
/// <returns>Task.</returns>
/// <exception cref="System.ArgumentNullException"></exception>
public async Task OnPlaybackStopped(BaseItem item, long? positionTicks, Guid sessionId)
/// <exception cref="System.ArgumentNullException">info</exception>
/// <exception cref="System.ArgumentOutOfRangeException">positionTicks</exception>
public async Task OnPlaybackStopped(PlaybackStopInfo info)
{
if (item == null)
if (info == null)
{
throw new ArgumentNullException();
throw new ArgumentNullException("info");
}
if (positionTicks.HasValue && positionTicks.Value < 0)
if (info.PositionTicks.HasValue && info.PositionTicks.Value < 0)
{
throw new ArgumentOutOfRangeException("positionTicks");
}
var session = Sessions.First(i => i.Id.Equals(sessionId));
var session = Sessions.First(i => i.Id.Equals(info.SessionId));
RemoveNowPlayingItem(session, item);
RemoveNowPlayingItem(session, info.Item);
var key = item.GetUserDataKey();
var key = info.Item.GetUserDataKey();
var user = session.User;
var data = _userDataRepository.GetUserData(user.Id, key);
if (positionTicks.HasValue)
if (info.PositionTicks.HasValue)
{
UpdatePlayState(item, data, positionTicks.Value);
UpdatePlayState(info.Item, data, info.PositionTicks.Value);
}
else
{
@ -356,9 +352,9 @@ namespace MediaBrowser.Server.Implementations.Session
EventHelper.QueueEventIfNotNull(PlaybackStopped, this, new PlaybackProgressEventArgs
{
Item = item,
Item = info.Item,
User = user,
PlaybackPositionTicks = positionTicks
PlaybackPositionTicks = info.PositionTicks
}, _logger);
}

View File

@ -128,7 +128,16 @@ namespace MediaBrowser.Server.Implementations.Session
var isPaused = vals.Length > 2 && string.Equals(vals[2], "true", StringComparison.OrdinalIgnoreCase);
var isMuted = vals.Length > 3 && string.Equals(vals[3], "true", StringComparison.OrdinalIgnoreCase);
_sessionManager.OnPlaybackProgress(item, positionTicks, isPaused, isMuted, session.Id);
var info = new PlaybackProgressInfo
{
Item = item,
PositionTicks = positionTicks,
IsMuted = isMuted,
IsPaused = isPaused,
SessionId = session.Id
};
_sessionManager.OnPlaybackProgress(info);
}
}
else if (string.Equals(message.MessageType, "PlaybackStopped", StringComparison.OrdinalIgnoreCase))
@ -155,7 +164,14 @@ namespace MediaBrowser.Server.Implementations.Session
}
}
_sessionManager.OnPlaybackStopped(item, positionTicks, session.Id);
var info = new PlaybackStopInfo
{
Item = item,
PositionTicks = positionTicks,
SessionId = session.Id
};
_sessionManager.OnPlaybackStopped(info);
}
}