Selaa lähdekoodia

control remote players with now playing bar

Luke Pulverenti 11 vuotta sitten
vanhempi
sitoutus
b6ca79b73f

+ 16 - 0
MediaBrowser.Controller/Session/ISessionController.cs

@@ -96,6 +96,22 @@ namespace MediaBrowser.Controller.Session
         /// <param name="cancellationToken">The cancellation token.</param>
         /// <returns>Task.</returns>
         Task SendSessionEndedNotification(SessionInfoDto sessionInfo, CancellationToken cancellationToken);
+
+        /// <summary>
+        /// Sends the playback start notification.
+        /// </summary>
+        /// <param name="sessionInfo">The session information.</param>
+        /// <param name="cancellationToken">The cancellation token.</param>
+        /// <returns>Task.</returns>
+        Task SendPlaybackStartNotification(SessionInfoDto sessionInfo, CancellationToken cancellationToken);
+
+        /// <summary>
+        /// Sends the playback start notification.
+        /// </summary>
+        /// <param name="sessionInfo">The session information.</param>
+        /// <param name="cancellationToken">The cancellation token.</param>
+        /// <returns>Task.</returns>
+        Task SendPlaybackStoppedNotification(SessionInfoDto sessionInfo, CancellationToken cancellationToken);
         
         /// <summary>
         /// Sends the server restart notification.

+ 10 - 0
MediaBrowser.Dlna/PlayTo/DlnaController.cs

@@ -331,6 +331,16 @@ namespace MediaBrowser.Dlna.PlayTo
             return Task.FromResult(true);
         }
 
+        public Task SendPlaybackStartNotification(SessionInfoDto sessionInfo, CancellationToken cancellationToken)
+        {
+            return Task.FromResult(true);
+        }
+
+        public Task SendPlaybackStoppedNotification(SessionInfoDto sessionInfo, CancellationToken cancellationToken)
+        {
+            return Task.FromResult(true);
+        }
+
         public Task SendServerShutdownNotification(CancellationToken cancellationToken)
         {
             return Task.FromResult(true);

+ 6 - 0
MediaBrowser.Model/Entities/BaseItemInfo.cs

@@ -46,6 +46,12 @@ namespace MediaBrowser.Model.Entities
         /// <value>The primary image tag.</value>
         public Guid? PrimaryImageTag { get; set; }
 
+        /// <summary>
+        /// Gets or sets the primary image item identifier.
+        /// </summary>
+        /// <value>The primary image item identifier.</value>
+        public string PrimaryImageItemId { get; set; }
+        
         /// <summary>
         /// Gets or sets the thumb image tag.
         /// </summary>

+ 2 - 1
MediaBrowser.Model/Session/GeneralCommand.cs

@@ -46,6 +46,7 @@ namespace MediaBrowser.Model.Session
         ToggleMute = 21,
         SetVolume = 22,
         SetAudioStreamIndex = 23,
-        SetSubtitleStreamIndex = 24
+        SetSubtitleStreamIndex = 24,
+        ToggleFullscreen = 25
     }
 }

+ 0 - 4
MediaBrowser.Model/Session/PlaystateCommand.cs

@@ -31,10 +31,6 @@ namespace MediaBrowser.Model.Session
         /// </summary>
         Seek,
         /// <summary>
-        /// The fullscreen
-        /// </summary>
-        Fullscreen,
-        /// <summary>
         /// The rewind
         /// </summary>
         Rewind,

+ 10 - 0
MediaBrowser.Server.Implementations/Roku/RokuSessionController.cs

@@ -46,6 +46,16 @@ namespace MediaBrowser.Server.Implementations.Roku
             return Task.FromResult(true);
         }
 
+        public Task SendPlaybackStartNotification(SessionInfoDto sessionInfo, CancellationToken cancellationToken)
+        {
+            return Task.FromResult(true);
+        }
+
+        public Task SendPlaybackStoppedNotification(SessionInfoDto sessionInfo, CancellationToken cancellationToken)
+        {
+            return Task.FromResult(true);
+        }
+
         public Task SendMessageCommand(MessageCommand command, CancellationToken cancellationToken)
         {
             return SendCommand(new WebSocketMessage<MessageCommand>

+ 51 - 1
MediaBrowser.Server.Implementations/Session/SessionManager.cs

@@ -444,6 +444,8 @@ namespace MediaBrowser.Server.Implementations.Session
                 MediaSourceId = info.MediaSourceId
 
             }, _logger);
+
+            await SendPlaybackStartNotification(session, CancellationToken.None).ConfigureAwait(false);
         }
 
         /// <summary>
@@ -583,6 +585,8 @@ namespace MediaBrowser.Server.Implementations.Session
                 MediaSourceId = mediaSourceId
 
             }, _logger);
+
+            await SendPlaybackStoppedNotification(session, CancellationToken.None).ConfigureAwait(false);
         }
 
         private string GetMediaSourceId(BaseItem item, string reportedMediaSourceId)
@@ -972,7 +976,6 @@ namespace MediaBrowser.Server.Implementations.Session
             return Task.WhenAll(tasks);
         }
 
-
         public Task SendSessionEndedNotification(SessionInfo sessionInfo, CancellationToken cancellationToken)
         {
             var sessions = Sessions.Where(i => i.IsActive && i.SessionController != null).ToList();
@@ -994,6 +997,48 @@ namespace MediaBrowser.Server.Implementations.Session
             return Task.WhenAll(tasks);
         }
 
+        public Task SendPlaybackStartNotification(SessionInfo sessionInfo, CancellationToken cancellationToken)
+        {
+            var sessions = Sessions.Where(i => i.IsActive && i.SessionController != null).ToList();
+            var dto = GetSessionInfoDto(sessionInfo);
+
+            var tasks = sessions.Select(session => Task.Run(async () =>
+            {
+                try
+                {
+                    await session.SessionController.SendPlaybackStartNotification(dto, cancellationToken).ConfigureAwait(false);
+                }
+                catch (Exception ex)
+                {
+                    _logger.ErrorException("Error in SendPlaybackStartNotification.", ex);
+                }
+
+            }, cancellationToken));
+
+            return Task.WhenAll(tasks);
+        }
+
+        public Task SendPlaybackStoppedNotification(SessionInfo sessionInfo, CancellationToken cancellationToken)
+        {
+            var sessions = Sessions.Where(i => i.IsActive && i.SessionController != null).ToList();
+            var dto = GetSessionInfoDto(sessionInfo);
+
+            var tasks = sessions.Select(session => Task.Run(async () =>
+            {
+                try
+                {
+                    await session.SessionController.SendPlaybackStoppedNotification(dto, cancellationToken).ConfigureAwait(false);
+                }
+                catch (Exception ex)
+                {
+                    _logger.ErrorException("Error in SendPlaybackStoppedNotification.", ex);
+                }
+
+            }, cancellationToken));
+
+            return Task.WhenAll(tasks);
+        }
+
         /// <summary>
         /// Adds the additional user.
         /// </summary>
@@ -1163,6 +1208,11 @@ namespace MediaBrowser.Server.Implementations.Session
 
             info.PrimaryImageTag = GetImageCacheTag(item, ImageType.Primary);
 
+            if (info.PrimaryImageTag.HasValue)
+            {
+                info.PrimaryImageItemId = GetDtoId(item);
+            }
+
             var backropItem = item.HasImage(ImageType.Backdrop) ? item : null;
 
             var thumbItem = item.HasImage(ImageType.Thumb) ? item : null;

+ 24 - 0
MediaBrowser.Server.Implementations/Session/WebSocketController.cs

@@ -210,5 +210,29 @@ namespace MediaBrowser.Server.Implementations.Session
 
             }, cancellationToken);
         }
+
+        public Task SendPlaybackStartNotification(SessionInfoDto sessionInfo, CancellationToken cancellationToken)
+        {
+            var socket = GetActiveSocket();
+
+            return socket.SendAsync(new WebSocketMessage<SessionInfoDto>
+            {
+                MessageType = "PlaybackStart",
+                Data = sessionInfo
+
+            }, cancellationToken);
+        }
+
+        public Task SendPlaybackStoppedNotification(SessionInfoDto sessionInfo, CancellationToken cancellationToken)
+        {
+            var socket = GetActiveSocket();
+
+            return socket.SendAsync(new WebSocketMessage<SessionInfoDto>
+            {
+                MessageType = "PlaybackStopped",
+                Data = sessionInfo
+
+            }, cancellationToken);
+        }
     }
 }