diff --git a/Emby.Server.Implementations/SyncPlay/Group.cs b/Emby.Server.Implementations/SyncPlay/Group.cs index 12efff261b..bc20ddff82 100644 --- a/Emby.Server.Implementations/SyncPlay/Group.cs +++ b/Emby.Server.Implementations/SyncPlay/Group.cs @@ -536,6 +536,16 @@ namespace Emby.Server.Implementations.SyncPlay return itemFound; } + /// + public void ClearPlayQueue(bool clearPlayingItem) + { + PlayQueue.ClearPlaylist(clearPlayingItem); + if (clearPlayingItem) + { + RestartCurrentItem(); + } + } + /// public bool RemoveFromPlayQueue(IReadOnlyList playlistItemIds) { diff --git a/Jellyfin.Api/Controllers/SyncPlayController.cs b/Jellyfin.Api/Controllers/SyncPlayController.cs index 1b3248c0c6..c6b70f3d20 100644 --- a/Jellyfin.Api/Controllers/SyncPlayController.cs +++ b/Jellyfin.Api/Controllers/SyncPlayController.cs @@ -162,7 +162,7 @@ namespace Jellyfin.Api.Controllers [FromBody, Required] RemoveFromPlaylistRequestDto requestData) { var currentSession = await RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request).ConfigureAwait(false); - var syncPlayRequest = new RemoveFromPlaylistGroupRequest(requestData.PlaylistItemIds); + var syncPlayRequest = new RemoveFromPlaylistGroupRequest(requestData.PlaylistItemIds, requestData.ClearPlaylist, requestData.ClearPlayingItem); _syncPlayManager.HandleRequest(currentSession, syncPlayRequest, CancellationToken.None); return NoContent(); } diff --git a/Jellyfin.Api/Models/SyncPlayDtos/RemoveFromPlaylistRequestDto.cs b/Jellyfin.Api/Models/SyncPlayDtos/RemoveFromPlaylistRequestDto.cs index e9b2b2cb37..02ce5a0488 100644 --- a/Jellyfin.Api/Models/SyncPlayDtos/RemoveFromPlaylistRequestDto.cs +++ b/Jellyfin.Api/Models/SyncPlayDtos/RemoveFromPlaylistRequestDto.cs @@ -17,9 +17,21 @@ namespace Jellyfin.Api.Models.SyncPlayDtos } /// - /// Gets or sets the playlist identifiers ot the items. + /// Gets or sets the playlist identifiers ot the items. Ignored when clearing the playlist. /// /// The playlist identifiers ot the items. public IReadOnlyList PlaylistItemIds { get; set; } + + /// + /// Gets or sets a value indicating whether the entire playlist should be cleared. + /// + /// Whether the entire playlist should be cleared. + public bool ClearPlaylist { get; set; } + + /// + /// Gets or sets a value indicating whether the playing item should be removed as well. Used only when clearing the playlist. + /// + /// Whether the playing item should be removed as well. + public bool ClearPlayingItem { get; set; } } } diff --git a/MediaBrowser.Controller/SyncPlay/GroupStates/AbstractGroupState.cs b/MediaBrowser.Controller/SyncPlay/GroupStates/AbstractGroupState.cs index 91a13fb28e..51c95a1bb2 100644 --- a/MediaBrowser.Controller/SyncPlay/GroupStates/AbstractGroupState.cs +++ b/MediaBrowser.Controller/SyncPlay/GroupStates/AbstractGroupState.cs @@ -68,7 +68,16 @@ namespace MediaBrowser.Controller.SyncPlay.GroupStates /// public virtual void HandleRequest(RemoveFromPlaylistGroupRequest request, IGroupStateContext context, GroupStateType prevState, SessionInfo session, CancellationToken cancellationToken) { - var playingItemRemoved = context.RemoveFromPlayQueue(request.PlaylistItemIds); + bool playingItemRemoved; + if (request.ClearPlaylist) + { + context.ClearPlayQueue(request.ClearPlayingItem); + playingItemRemoved = request.ClearPlayingItem; + } + else + { + playingItemRemoved = context.RemoveFromPlayQueue(request.PlaylistItemIds); + } var playQueueUpdate = context.GetPlayQueueUpdate(PlayQueueUpdateReason.RemoveItems); var update = context.NewSyncPlayGroupUpdate(GroupUpdateType.PlayQueue, playQueueUpdate); diff --git a/MediaBrowser.Controller/SyncPlay/IGroupStateContext.cs b/MediaBrowser.Controller/SyncPlay/IGroupStateContext.cs index de26c7d9ef..d2de224503 100644 --- a/MediaBrowser.Controller/SyncPlay/IGroupStateContext.cs +++ b/MediaBrowser.Controller/SyncPlay/IGroupStateContext.cs @@ -162,6 +162,12 @@ namespace MediaBrowser.Controller.SyncPlay /// true if the play queue has been changed; false if something went wrong. bool SetPlayingItem(Guid playlistItemId); + /// + /// Clears the play queue. + /// + /// Whether to remove the playing item as well. + void ClearPlayQueue(bool clearPlayingItem); + /// /// Removes items from the play queue. /// diff --git a/MediaBrowser.Controller/SyncPlay/PlaybackRequests/RemoveFromPlaylistGroupRequest.cs b/MediaBrowser.Controller/SyncPlay/PlaybackRequests/RemoveFromPlaylistGroupRequest.cs index 6891452934..856f175df3 100644 --- a/MediaBrowser.Controller/SyncPlay/PlaybackRequests/RemoveFromPlaylistGroupRequest.cs +++ b/MediaBrowser.Controller/SyncPlay/PlaybackRequests/RemoveFromPlaylistGroupRequest.cs @@ -17,9 +17,14 @@ namespace MediaBrowser.Controller.SyncPlay.PlaybackRequests /// Initializes a new instance of the class. /// /// The playlist ids of the items to remove. - public RemoveFromPlaylistGroupRequest(IReadOnlyList items) + /// Whether to clear the entire playlist. The items list will be ignored. + /// Whether to remove the playing item as well. Used only when clearing the playlist. + + public RemoveFromPlaylistGroupRequest(IReadOnlyList items, bool clearPlaylist = false, bool clearPlayingItem = false) { PlaylistItemIds = items ?? Array.Empty(); + ClearPlaylist = clearPlaylist; + ClearPlayingItem = clearPlayingItem; } /// @@ -28,6 +33,18 @@ namespace MediaBrowser.Controller.SyncPlay.PlaybackRequests /// The playlist identifiers ot the items. public IReadOnlyList PlaylistItemIds { get; } + /// + /// Gets a value indicating whether the entire playlist should be cleared. + /// + /// Whether the entire playlist should be cleared. + public bool ClearPlaylist { get; } + + /// + /// Gets a value indicating whether the playing item should be removed as well. + /// + /// Whether the playing item should be removed as well. + public bool ClearPlayingItem { get; } + /// public override PlaybackRequestType Action { get; } = PlaybackRequestType.RemoveFromPlaylist;