aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/SyncPlay/GroupController.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Emby.Server.Implementations/SyncPlay/GroupController.cs')
-rw-r--r--Emby.Server.Implementations/SyncPlay/GroupController.cs71
1 files changed, 47 insertions, 24 deletions
diff --git a/Emby.Server.Implementations/SyncPlay/GroupController.cs b/Emby.Server.Implementations/SyncPlay/GroupController.cs
index 2d8668014..01e116617 100644
--- a/Emby.Server.Implementations/SyncPlay/GroupController.cs
+++ b/Emby.Server.Implementations/SyncPlay/GroupController.cs
@@ -127,16 +127,6 @@ namespace Emby.Server.Implementations.SyncPlay
}
/// <summary>
- /// Checks if a session is in this group.
- /// </summary>
- /// <param name="sessionId">The session identifier to check.</param>
- /// <returns><c>true</c> if the session is in this group; <c>false</c> otherwise.</returns>
- private bool ContainsSession(string sessionId)
- {
- return Participants.ContainsKey(sessionId);
- }
-
- /// <summary>
/// Adds the session to the group.
/// </summary>
/// <param name="session">The session.</param>
@@ -179,13 +169,17 @@ namespace Emby.Server.Implementations.SyncPlay
.Select(session => session.Session)
.ToArray();
case SyncPlayBroadcastType.AllExceptCurrentSession:
- return Participants.Values.Select(
- session => session.Session).Where(
- session => !session.Id.Equals(from.Id)).ToArray();
+ return Participants
+ .Values
+ .Select(session => session.Session)
+ .Where(session => !session.Id.Equals(from.Id))
+ .ToArray();
case SyncPlayBroadcastType.AllReady:
- return Participants.Values.Where(
- session => !session.IsBuffering).Select(
- session => session.Session).ToArray();
+ return Participants
+ .Values
+ .Where(session => !session.IsBuffering)
+ .Select(session => session.Session)
+ .ToArray();
default:
return Array.Empty<SessionInfo>();
}
@@ -238,7 +232,8 @@ namespace Emby.Server.Implementations.SyncPlay
}
// Get list of users.
- var users = Participants.Values
+ var users = Participants
+ .Values
.Select(participant => _userManager.GetUserById(participant.Session.UserId));
// Find problematic users.
@@ -265,6 +260,7 @@ namespace Emby.Server.Implementations.SyncPlay
if (sessionIsPlayingAnItem)
{
var playlist = session.NowPlayingQueue.Select(item => item.Id).ToArray();
+ PlayQueue.Reset();
PlayQueue.SetPlaylist(playlist);
PlayQueue.SetPlayingItemById(session.FullNowPlayingItem.Id);
RunTimeTicks = session.FullNowPlayingItem.RunTimeTicks ?? 0;
@@ -366,7 +362,7 @@ namespace Emby.Server.Implementations.SyncPlay
/// <inheritdoc />
public void SetIgnoreGroupWait(SessionInfo session, bool ignoreGroupWait)
{
- if (!ContainsSession(session.Id))
+ if (!Participants.ContainsKey(session.Id))
{
return;
}
@@ -444,8 +440,8 @@ namespace Emby.Server.Implementations.SyncPlay
public long SanitizePositionTicks(long? positionTicks)
{
var ticks = positionTicks ?? 0;
- ticks = ticks >= 0 ? ticks : 0;
- ticks = ticks > RunTimeTicks ? RunTimeTicks : ticks;
+ ticks = Math.Max(ticks, 0);
+ ticks = Math.Min(ticks, RunTimeTicks);
return ticks;
}
@@ -517,6 +513,7 @@ namespace Emby.Server.Implementations.SyncPlay
return false;
}
+ PlayQueue.Reset();
PlayQueue.SetPlaylist(playQueue);
PlayQueue.SetPlayingItemByIndex(playingItemPosition);
var item = _libraryManager.GetItemById(PlayQueue.GetPlayingItemId());
@@ -646,12 +643,33 @@ namespace Emby.Server.Implementations.SyncPlay
/// <inheritdoc />
public void SetRepeatMode(string mode) {
- PlayQueue.SetRepeatMode(mode);
+ switch (mode)
+ {
+ case "RepeatOne":
+ PlayQueue.SetRepeatMode(GroupRepeatMode.RepeatOne);
+ break;
+ case "RepeatAll":
+ PlayQueue.SetRepeatMode(GroupRepeatMode.RepeatAll);
+ break;
+ default:
+ // On unknown values, default to repeat none.
+ PlayQueue.SetRepeatMode(GroupRepeatMode.RepeatNone);
+ break;
+ }
}
/// <inheritdoc />
public void SetShuffleMode(string mode) {
- PlayQueue.SetShuffleMode(mode);
+ switch (mode)
+ {
+ case "Shuffle":
+ PlayQueue.SetShuffleMode(GroupShuffleMode.Shuffle);
+ break;
+ default:
+ // On unknown values, default to sorted playlist.
+ PlayQueue.SetShuffleMode(GroupShuffleMode.Sorted);
+ break;
+ }
}
/// <inheritdoc />
@@ -663,8 +681,13 @@ namespace Emby.Server.Implementations.SyncPlay
{
var currentTime = DateTime.UtcNow;
var elapsedTime = currentTime - LastActivity;
- // Event may happen during the delay added to account for latency.
- startPositionTicks += elapsedTime.Ticks > 0 ? elapsedTime.Ticks : 0;
+ // Elapsed time is negative if event happens
+ // during the delay added to account for latency.
+ // In this phase clients haven't started the playback yet.
+ // In other words, LastActivity is in the future,
+ // when playback unpause is supposed to happen.
+ // Adjust ticks only if playback actually started.
+ startPositionTicks += Math.Max(elapsedTime.Ticks, 0);
}
return new PlayQueueUpdate()