Selaa lähdekoodia

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

Luke Pulverenti 11 vuotta sitten
vanhempi
sitoutus
29fd559f0a

+ 18 - 2
MediaBrowser.Api/UserLibrary/UserLibraryService.cs

@@ -697,7 +697,16 @@ namespace MediaBrowser.Api.UserLibrary
 
 
             var item = _dtoService.GetItemByDtoId(request.Id, user.Id);
             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);
             Task.WaitAll(task);
         }
         }
@@ -717,7 +726,14 @@ namespace MediaBrowser.Api.UserLibrary
 
 
             var session = GetSession();
             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);
             Task.WaitAll(task);
         }
         }

+ 2 - 0
MediaBrowser.Controller/MediaBrowser.Controller.csproj

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

+ 4 - 10
MediaBrowser.Controller/Session/ISessionManager.cs

@@ -62,24 +62,18 @@ namespace MediaBrowser.Controller.Session
         /// <summary>
         /// <summary>
         /// Used to report playback progress for an item
         /// Used to report playback progress for an item
         /// </summary>
         /// </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>
         /// <returns>Task.</returns>
         /// <exception cref="System.ArgumentNullException"></exception>
         /// <exception cref="System.ArgumentNullException"></exception>
-        Task OnPlaybackProgress(BaseItem item, long? positionTicks, bool isPaused, bool isMuted, Guid sessionId);
+        Task OnPlaybackProgress(PlaybackProgressInfo info);
 
 
         /// <summary>
         /// <summary>
         /// Used to report that playback has ended for an item
         /// Used to report that playback has ended for an item
         /// </summary>
         /// </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>
         /// <returns>Task.</returns>
         /// <exception cref="System.ArgumentNullException"></exception>
         /// <exception cref="System.ArgumentNullException"></exception>
-        Task OnPlaybackStopped(BaseItem item, long? positionTicks, Guid sessionId);
+        Task OnPlaybackStopped(PlaybackStopInfo info);
 
 
         /// <summary>
         /// <summary>
         /// Sends the system command.
         /// Sends the system command.

+ 38 - 0
MediaBrowser.Controller/Session/PlaybackProgressInfo.cs

@@ -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; }
+    }
+}

+ 26 - 0
MediaBrowser.Controller/Session/PlaybackStopInfo.cs

@@ -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; }
+    }
+}

+ 26 - 30
MediaBrowser.Server.Implementations/Session/SessionManager.cs

@@ -266,46 +266,43 @@ namespace MediaBrowser.Server.Implementations.Session
         /// <summary>
         /// <summary>
         /// Used to report playback progress for an item
         /// Used to report playback progress for an item
         /// </summary>
         /// </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>
         /// <returns>Task.</returns>
         /// <exception cref="System.ArgumentNullException"></exception>
         /// <exception cref="System.ArgumentNullException"></exception>
         /// <exception cref="System.ArgumentOutOfRangeException">positionTicks</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");
                 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;
             var user = session.User;
 
 
-            if (positionTicks.HasValue)
+            if (info.PositionTicks.HasValue)
             {
             {
                 var data = _userDataRepository.GetUserData(user.Id, key);
                 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);
                 await _userDataRepository.SaveUserData(user.Id, key, data, CancellationToken.None).ConfigureAwait(false);
             }
             }
 
 
             EventHelper.QueueEventIfNotNull(PlaybackProgress, this, new PlaybackProgressEventArgs
             EventHelper.QueueEventIfNotNull(PlaybackProgress, this, new PlaybackProgressEventArgs
             {
             {
-                Item = item,
+                Item = info.Item,
                 User = user,
                 User = user,
-                PlaybackPositionTicks = positionTicks
+                PlaybackPositionTicks = info.PositionTicks
 
 
             }, _logger);
             }, _logger);
         }
         }
@@ -313,36 +310,35 @@ namespace MediaBrowser.Server.Implementations.Session
         /// <summary>
         /// <summary>
         /// Used to report that playback has ended for an item
         /// Used to report that playback has ended for an item
         /// </summary>
         /// </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>
         /// <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");
                 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 user = session.User;
 
 
             var data = _userDataRepository.GetUserData(user.Id, key);
             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
             else
             {
             {
@@ -356,9 +352,9 @@ namespace MediaBrowser.Server.Implementations.Session
 
 
             EventHelper.QueueEventIfNotNull(PlaybackStopped, this, new PlaybackProgressEventArgs
             EventHelper.QueueEventIfNotNull(PlaybackStopped, this, new PlaybackProgressEventArgs
             {
             {
-                Item = item,
+                Item = info.Item,
                 User = user,
                 User = user,
-                PlaybackPositionTicks = positionTicks
+                PlaybackPositionTicks = info.PositionTicks
             }, _logger);
             }, _logger);
         }
         }
 
 

+ 18 - 2
MediaBrowser.Server.Implementations/Session/SessionWebSocketListener.cs

@@ -128,7 +128,16 @@ namespace MediaBrowser.Server.Implementations.Session
                     var isPaused = vals.Length > 2 && string.Equals(vals[2], "true", StringComparison.OrdinalIgnoreCase);
                     var isPaused = vals.Length > 2 && string.Equals(vals[2], "true", StringComparison.OrdinalIgnoreCase);
                     var isMuted = vals.Length > 3 && string.Equals(vals[3], "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))
             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);
                 }
                 }
             }
             }