Group.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. #nullable disable
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. using Jellyfin.Database.Implementations.Entities;
  8. using Jellyfin.Extensions;
  9. using MediaBrowser.Controller.Library;
  10. using MediaBrowser.Controller.Session;
  11. using MediaBrowser.Controller.SyncPlay;
  12. using MediaBrowser.Controller.SyncPlay.GroupStates;
  13. using MediaBrowser.Controller.SyncPlay.Queue;
  14. using MediaBrowser.Controller.SyncPlay.Requests;
  15. using MediaBrowser.Model.SyncPlay;
  16. using Microsoft.Extensions.Logging;
  17. namespace Emby.Server.Implementations.SyncPlay
  18. {
  19. /// <summary>
  20. /// Class Group.
  21. /// </summary>
  22. /// <remarks>
  23. /// Class is not thread-safe, external locking is required when accessing methods.
  24. /// </remarks>
  25. public class Group : IGroupStateContext
  26. {
  27. /// <summary>
  28. /// The logger.
  29. /// </summary>
  30. private readonly ILogger<Group> _logger;
  31. /// <summary>
  32. /// The logger factory.
  33. /// </summary>
  34. private readonly ILoggerFactory _loggerFactory;
  35. /// <summary>
  36. /// The user manager.
  37. /// </summary>
  38. private readonly IUserManager _userManager;
  39. /// <summary>
  40. /// The session manager.
  41. /// </summary>
  42. private readonly ISessionManager _sessionManager;
  43. /// <summary>
  44. /// The library manager.
  45. /// </summary>
  46. private readonly ILibraryManager _libraryManager;
  47. /// <summary>
  48. /// The participants, or members of the group.
  49. /// </summary>
  50. private readonly Dictionary<string, GroupMember> _participants =
  51. new Dictionary<string, GroupMember>(StringComparer.OrdinalIgnoreCase);
  52. /// <summary>
  53. /// The internal group state.
  54. /// </summary>
  55. private IGroupState _state;
  56. /// <summary>
  57. /// Initializes a new instance of the <see cref="Group" /> class.
  58. /// </summary>
  59. /// <param name="loggerFactory">The logger factory.</param>
  60. /// <param name="userManager">The user manager.</param>
  61. /// <param name="sessionManager">The session manager.</param>
  62. /// <param name="libraryManager">The library manager.</param>
  63. public Group(
  64. ILoggerFactory loggerFactory,
  65. IUserManager userManager,
  66. ISessionManager sessionManager,
  67. ILibraryManager libraryManager)
  68. {
  69. _loggerFactory = loggerFactory;
  70. _userManager = userManager;
  71. _sessionManager = sessionManager;
  72. _libraryManager = libraryManager;
  73. _logger = loggerFactory.CreateLogger<Group>();
  74. _state = new IdleGroupState(loggerFactory);
  75. }
  76. /// <summary>
  77. /// Gets the default ping value used for sessions.
  78. /// </summary>
  79. /// <value>The default ping.</value>
  80. public long DefaultPing { get; } = 500;
  81. /// <summary>
  82. /// Gets the maximum time offset error accepted for dates reported by clients, in milliseconds.
  83. /// </summary>
  84. /// <value>The maximum time offset error.</value>
  85. public long TimeSyncOffset { get; } = 2000;
  86. /// <summary>
  87. /// Gets the maximum offset error accepted for position reported by clients, in milliseconds.
  88. /// </summary>
  89. /// <value>The maximum offset error.</value>
  90. public long MaxPlaybackOffset { get; } = 500;
  91. /// <summary>
  92. /// Gets the group identifier.
  93. /// </summary>
  94. /// <value>The group identifier.</value>
  95. public Guid GroupId { get; } = Guid.NewGuid();
  96. /// <summary>
  97. /// Gets the group name.
  98. /// </summary>
  99. /// <value>The group name.</value>
  100. public string GroupName { get; private set; }
  101. /// <summary>
  102. /// Gets the group identifier.
  103. /// </summary>
  104. /// <value>The group identifier.</value>
  105. public PlayQueueManager PlayQueue { get; } = new PlayQueueManager();
  106. /// <summary>
  107. /// Gets the runtime ticks of current playing item.
  108. /// </summary>
  109. /// <value>The runtime ticks of current playing item.</value>
  110. public long RunTimeTicks { get; private set; }
  111. /// <summary>
  112. /// Gets or sets the position ticks.
  113. /// </summary>
  114. /// <value>The position ticks.</value>
  115. public long PositionTicks { get; set; }
  116. /// <summary>
  117. /// Gets or sets the last activity.
  118. /// </summary>
  119. /// <value>The last activity.</value>
  120. public DateTime LastActivity { get; set; }
  121. /// <summary>
  122. /// Adds the session to the group.
  123. /// </summary>
  124. /// <param name="session">The session.</param>
  125. private void AddSession(SessionInfo session)
  126. {
  127. _participants.TryAdd(
  128. session.Id,
  129. new GroupMember(session)
  130. {
  131. Ping = DefaultPing,
  132. IsBuffering = false
  133. });
  134. }
  135. /// <summary>
  136. /// Removes the session from the group.
  137. /// </summary>
  138. /// <param name="session">The session.</param>
  139. private void RemoveSession(SessionInfo session)
  140. {
  141. _participants.Remove(session.Id);
  142. }
  143. /// <summary>
  144. /// Filters sessions of this group.
  145. /// </summary>
  146. /// <param name="fromId">The current session identifier.</param>
  147. /// <param name="type">The filtering type.</param>
  148. /// <returns>The list of sessions matching the filter.</returns>
  149. private IEnumerable<string> FilterSessions(string fromId, SyncPlayBroadcastType type)
  150. {
  151. return type switch
  152. {
  153. SyncPlayBroadcastType.CurrentSession => new string[] { fromId },
  154. SyncPlayBroadcastType.AllGroup => _participants
  155. .Values
  156. .Select(member => member.SessionId),
  157. SyncPlayBroadcastType.AllExceptCurrentSession => _participants
  158. .Values
  159. .Select(member => member.SessionId)
  160. .Where(sessionId => !sessionId.Equals(fromId, StringComparison.OrdinalIgnoreCase)),
  161. SyncPlayBroadcastType.AllReady => _participants
  162. .Values
  163. .Where(member => !member.IsBuffering)
  164. .Select(member => member.SessionId),
  165. _ => Enumerable.Empty<string>()
  166. };
  167. }
  168. /// <summary>
  169. /// Checks if a given user can access all items of a given queue, that is,
  170. /// the user has the required minimum parental access and has access to all required folders.
  171. /// </summary>
  172. /// <param name="user">The user.</param>
  173. /// <param name="queue">The queue.</param>
  174. /// <returns><c>true</c> if the user can access all the items in the queue, <c>false</c> otherwise.</returns>
  175. private bool HasAccessToQueue(User user, IReadOnlyList<Guid> queue)
  176. {
  177. // Check if queue is empty.
  178. if (queue is null || queue.Count == 0)
  179. {
  180. return true;
  181. }
  182. foreach (var itemId in queue)
  183. {
  184. var item = _libraryManager.GetItemById(itemId);
  185. if (!item.IsVisibleStandalone(user))
  186. {
  187. return false;
  188. }
  189. }
  190. return true;
  191. }
  192. private bool AllUsersHaveAccessToQueue(IReadOnlyList<Guid> queue)
  193. {
  194. // Check if queue is empty.
  195. if (queue is null || queue.Count == 0)
  196. {
  197. return true;
  198. }
  199. // Get list of users.
  200. var users = _participants
  201. .Values
  202. .Select(participant => _userManager.GetUserById(participant.UserId));
  203. // Find problematic users.
  204. var usersWithNoAccess = users.Where(user => !HasAccessToQueue(user, queue));
  205. // All users must be able to access the queue.
  206. return !usersWithNoAccess.Any();
  207. }
  208. /// <summary>
  209. /// Checks if the group is empty.
  210. /// </summary>
  211. /// <returns><c>true</c> if the group is empty, <c>false</c> otherwise.</returns>
  212. public bool IsGroupEmpty() => _participants.Count == 0;
  213. /// <summary>
  214. /// Initializes the group with the session's info.
  215. /// </summary>
  216. /// <param name="session">The session.</param>
  217. /// <param name="request">The request.</param>
  218. /// <param name="cancellationToken">The cancellation token.</param>
  219. public void CreateGroup(SessionInfo session, NewGroupRequest request, CancellationToken cancellationToken)
  220. {
  221. GroupName = request.GroupName;
  222. AddSession(session);
  223. var sessionIsPlayingAnItem = session.FullNowPlayingItem is not null;
  224. RestartCurrentItem();
  225. if (sessionIsPlayingAnItem)
  226. {
  227. var playlist = session.NowPlayingQueue.Select(item => item.Id).ToList();
  228. PlayQueue.Reset();
  229. PlayQueue.SetPlaylist(playlist);
  230. PlayQueue.SetPlayingItemById(session.FullNowPlayingItem.Id);
  231. RunTimeTicks = session.FullNowPlayingItem.RunTimeTicks ?? 0;
  232. PositionTicks = session.PlayState.PositionTicks ?? 0;
  233. // Maintain playstate.
  234. var waitingState = new WaitingGroupState(_loggerFactory)
  235. {
  236. ResumePlaying = !session.PlayState.IsPaused
  237. };
  238. SetState(waitingState);
  239. }
  240. var updateSession = new SyncPlayGroupJoinedUpdate(GroupId, GetInfo());
  241. SendGroupUpdate(session, SyncPlayBroadcastType.CurrentSession, updateSession, cancellationToken);
  242. _state.SessionJoined(this, _state.Type, session, cancellationToken);
  243. _logger.LogInformation("Session {SessionId} created group {GroupId}.", session.Id, GroupId.ToString());
  244. }
  245. /// <summary>
  246. /// Adds the session to the group.
  247. /// </summary>
  248. /// <param name="session">The session.</param>
  249. /// <param name="request">The request.</param>
  250. /// <param name="cancellationToken">The cancellation token.</param>
  251. public void SessionJoin(SessionInfo session, JoinGroupRequest request, CancellationToken cancellationToken)
  252. {
  253. AddSession(session);
  254. var updateSession = new SyncPlayGroupJoinedUpdate(GroupId, GetInfo());
  255. SendGroupUpdate(session, SyncPlayBroadcastType.CurrentSession, updateSession, cancellationToken);
  256. var updateOthers = new SyncPlayUserJoinedUpdate(GroupId, session.UserName);
  257. SendGroupUpdate(session, SyncPlayBroadcastType.AllExceptCurrentSession, updateOthers, cancellationToken);
  258. _state.SessionJoined(this, _state.Type, session, cancellationToken);
  259. _logger.LogInformation("Session {SessionId} joined group {GroupId}.", session.Id, GroupId.ToString());
  260. }
  261. /// <summary>
  262. /// Removes the session from the group.
  263. /// </summary>
  264. /// <param name="session">The session.</param>
  265. /// <param name="request">The request.</param>
  266. /// <param name="cancellationToken">The cancellation token.</param>
  267. public void SessionLeave(SessionInfo session, LeaveGroupRequest request, CancellationToken cancellationToken)
  268. {
  269. _state.SessionLeaving(this, _state.Type, session, cancellationToken);
  270. RemoveSession(session);
  271. var updateSession = new SyncPlayGroupLeftUpdate(GroupId, GroupId.ToString());
  272. SendGroupUpdate(session, SyncPlayBroadcastType.CurrentSession, updateSession, cancellationToken);
  273. var updateOthers = new SyncPlayUserLeftUpdate(GroupId, session.UserName);
  274. SendGroupUpdate(session, SyncPlayBroadcastType.AllExceptCurrentSession, updateOthers, cancellationToken);
  275. _logger.LogInformation("Session {SessionId} left group {GroupId}.", session.Id, GroupId.ToString());
  276. }
  277. /// <summary>
  278. /// Handles the requested action by the session.
  279. /// </summary>
  280. /// <param name="session">The session.</param>
  281. /// <param name="request">The requested action.</param>
  282. /// <param name="cancellationToken">The cancellation token.</param>
  283. public void HandleRequest(SessionInfo session, IGroupPlaybackRequest request, CancellationToken cancellationToken)
  284. {
  285. // The server's job is to maintain a consistent state for clients to reference
  286. // and notify clients of state changes. The actual syncing of media playback
  287. // happens client side. Clients are aware of the server's time and use it to sync.
  288. _logger.LogInformation("Session {SessionId} requested {RequestType} in group {GroupId} that is {StateType}.", session.Id, request.Action, GroupId.ToString(), _state.Type);
  289. // Apply requested changes to this group given its current state.
  290. // Every request has a slightly different outcome depending on the group's state.
  291. // There are currently four different group states that accomplish different goals:
  292. // - Idle: in this state no media is playing and clients should be idle (playback is stopped).
  293. // - Waiting: in this state the group is waiting for all the clients to be ready to start the playback,
  294. // that is, they've either finished loading the media for the first time or they've finished buffering.
  295. // Once all clients report to be ready the group's state can change to Playing or Paused.
  296. // - Playing: clients have some media loaded and playback is unpaused.
  297. // - Paused: clients have some media loaded but playback is currently paused.
  298. request.Apply(this, _state, session, cancellationToken);
  299. }
  300. /// <summary>
  301. /// Gets the info about the group for the clients.
  302. /// </summary>
  303. /// <returns>The group info for the clients.</returns>
  304. public GroupInfoDto GetInfo()
  305. {
  306. var participants = _participants.Values.Select(session => session.UserName).Distinct().ToList();
  307. return new GroupInfoDto(GroupId, GroupName, _state.Type, participants, DateTime.UtcNow);
  308. }
  309. /// <summary>
  310. /// Checks if a user has access to all content in the play queue.
  311. /// </summary>
  312. /// <param name="user">The user.</param>
  313. /// <returns><c>true</c> if the user can access the play queue; <c>false</c> otherwise.</returns>
  314. public bool HasAccessToPlayQueue(User user)
  315. {
  316. var items = PlayQueue.GetPlaylist().Select(item => item.ItemId).ToList();
  317. return HasAccessToQueue(user, items);
  318. }
  319. /// <inheritdoc />
  320. public void SetIgnoreGroupWait(SessionInfo session, bool ignoreGroupWait)
  321. {
  322. if (_participants.TryGetValue(session.Id, out GroupMember value))
  323. {
  324. value.IgnoreGroupWait = ignoreGroupWait;
  325. }
  326. }
  327. /// <inheritdoc />
  328. public void SetState(IGroupState state)
  329. {
  330. _logger.LogInformation("Group {GroupId} switching from {FromStateType} to {ToStateType}.", GroupId.ToString(), _state.Type, state.Type);
  331. this._state = state;
  332. }
  333. /// <inheritdoc />
  334. public Task SendGroupUpdate<T>(SessionInfo from, SyncPlayBroadcastType type, GroupUpdate<T> message, CancellationToken cancellationToken)
  335. {
  336. IEnumerable<Task> GetTasks()
  337. {
  338. foreach (var sessionId in FilterSessions(from.Id, type))
  339. {
  340. yield return _sessionManager.SendSyncPlayGroupUpdate(sessionId, message, cancellationToken);
  341. }
  342. }
  343. return Task.WhenAll(GetTasks());
  344. }
  345. /// <inheritdoc />
  346. public Task SendCommand(SessionInfo from, SyncPlayBroadcastType type, SendCommand message, CancellationToken cancellationToken)
  347. {
  348. IEnumerable<Task> GetTasks()
  349. {
  350. foreach (var sessionId in FilterSessions(from.Id, type))
  351. {
  352. yield return _sessionManager.SendSyncPlayCommand(sessionId, message, cancellationToken);
  353. }
  354. }
  355. return Task.WhenAll(GetTasks());
  356. }
  357. /// <inheritdoc />
  358. public SendCommand NewSyncPlayCommand(SendCommandType type)
  359. {
  360. return new SendCommand(
  361. GroupId,
  362. PlayQueue.GetPlayingItemPlaylistId(),
  363. LastActivity,
  364. type,
  365. PositionTicks,
  366. DateTime.UtcNow);
  367. }
  368. /// <inheritdoc />
  369. public long SanitizePositionTicks(long? positionTicks)
  370. {
  371. var ticks = positionTicks ?? 0;
  372. return Math.Clamp(ticks, 0, RunTimeTicks);
  373. }
  374. /// <inheritdoc />
  375. public void UpdatePing(SessionInfo session, long ping)
  376. {
  377. if (_participants.TryGetValue(session.Id, out GroupMember value))
  378. {
  379. value.Ping = ping;
  380. }
  381. }
  382. /// <inheritdoc />
  383. public long GetHighestPing()
  384. {
  385. long max = long.MinValue;
  386. foreach (var session in _participants.Values)
  387. {
  388. max = Math.Max(max, session.Ping);
  389. }
  390. return max;
  391. }
  392. /// <inheritdoc />
  393. public void SetBuffering(SessionInfo session, bool isBuffering)
  394. {
  395. if (_participants.TryGetValue(session.Id, out GroupMember value))
  396. {
  397. value.IsBuffering = isBuffering;
  398. }
  399. }
  400. /// <inheritdoc />
  401. public void SetAllBuffering(bool isBuffering)
  402. {
  403. foreach (var session in _participants.Values)
  404. {
  405. session.IsBuffering = isBuffering;
  406. }
  407. }
  408. /// <inheritdoc />
  409. public bool IsBuffering()
  410. {
  411. foreach (var session in _participants.Values)
  412. {
  413. if (session.IsBuffering && !session.IgnoreGroupWait)
  414. {
  415. return true;
  416. }
  417. }
  418. return false;
  419. }
  420. /// <inheritdoc />
  421. public bool SetPlayQueue(IReadOnlyList<Guid> playQueue, int playingItemPosition, long startPositionTicks)
  422. {
  423. // Ignore on empty queue or invalid item position.
  424. if (playQueue.Count == 0 || playingItemPosition >= playQueue.Count || playingItemPosition < 0)
  425. {
  426. return false;
  427. }
  428. // Check if participants can access the new playing queue.
  429. if (!AllUsersHaveAccessToQueue(playQueue))
  430. {
  431. return false;
  432. }
  433. PlayQueue.Reset();
  434. PlayQueue.SetPlaylist(playQueue);
  435. PlayQueue.SetPlayingItemByIndex(playingItemPosition);
  436. var item = _libraryManager.GetItemById(PlayQueue.GetPlayingItemId());
  437. RunTimeTicks = item.RunTimeTicks ?? 0;
  438. PositionTicks = startPositionTicks;
  439. LastActivity = DateTime.UtcNow;
  440. return true;
  441. }
  442. /// <inheritdoc />
  443. public bool SetPlayingItem(Guid playlistItemId)
  444. {
  445. var itemFound = PlayQueue.SetPlayingItemByPlaylistId(playlistItemId);
  446. if (itemFound)
  447. {
  448. var item = _libraryManager.GetItemById(PlayQueue.GetPlayingItemId());
  449. RunTimeTicks = item.RunTimeTicks ?? 0;
  450. }
  451. else
  452. {
  453. RunTimeTicks = 0;
  454. }
  455. RestartCurrentItem();
  456. return itemFound;
  457. }
  458. /// <inheritdoc />
  459. public void ClearPlayQueue(bool clearPlayingItem)
  460. {
  461. PlayQueue.ClearPlaylist(clearPlayingItem);
  462. if (clearPlayingItem)
  463. {
  464. RestartCurrentItem();
  465. }
  466. }
  467. /// <inheritdoc />
  468. public bool RemoveFromPlayQueue(IReadOnlyList<Guid> playlistItemIds)
  469. {
  470. var playingItemRemoved = PlayQueue.RemoveFromPlaylist(playlistItemIds);
  471. if (playingItemRemoved)
  472. {
  473. var itemId = PlayQueue.GetPlayingItemId();
  474. if (!itemId.IsEmpty())
  475. {
  476. var item = _libraryManager.GetItemById(itemId);
  477. RunTimeTicks = item.RunTimeTicks ?? 0;
  478. }
  479. else
  480. {
  481. RunTimeTicks = 0;
  482. }
  483. RestartCurrentItem();
  484. }
  485. return playingItemRemoved;
  486. }
  487. /// <inheritdoc />
  488. public bool MoveItemInPlayQueue(Guid playlistItemId, int newIndex)
  489. {
  490. return PlayQueue.MovePlaylistItem(playlistItemId, newIndex);
  491. }
  492. /// <inheritdoc />
  493. public bool AddToPlayQueue(IReadOnlyList<Guid> newItems, GroupQueueMode mode)
  494. {
  495. // Ignore on empty list.
  496. if (newItems.Count == 0)
  497. {
  498. return false;
  499. }
  500. // Check if participants can access the new playing queue.
  501. if (!AllUsersHaveAccessToQueue(newItems))
  502. {
  503. return false;
  504. }
  505. if (mode.Equals(GroupQueueMode.QueueNext))
  506. {
  507. PlayQueue.QueueNext(newItems);
  508. }
  509. else
  510. {
  511. PlayQueue.Queue(newItems);
  512. }
  513. return true;
  514. }
  515. /// <inheritdoc />
  516. public void RestartCurrentItem()
  517. {
  518. PositionTicks = 0;
  519. LastActivity = DateTime.UtcNow;
  520. }
  521. /// <inheritdoc />
  522. public bool NextItemInQueue()
  523. {
  524. var update = PlayQueue.Next();
  525. if (update)
  526. {
  527. var item = _libraryManager.GetItemById(PlayQueue.GetPlayingItemId());
  528. RunTimeTicks = item.RunTimeTicks ?? 0;
  529. RestartCurrentItem();
  530. return true;
  531. }
  532. return false;
  533. }
  534. /// <inheritdoc />
  535. public bool PreviousItemInQueue()
  536. {
  537. var update = PlayQueue.Previous();
  538. if (update)
  539. {
  540. var item = _libraryManager.GetItemById(PlayQueue.GetPlayingItemId());
  541. RunTimeTicks = item.RunTimeTicks ?? 0;
  542. RestartCurrentItem();
  543. return true;
  544. }
  545. return false;
  546. }
  547. /// <inheritdoc />
  548. public void SetRepeatMode(GroupRepeatMode mode)
  549. {
  550. PlayQueue.SetRepeatMode(mode);
  551. }
  552. /// <inheritdoc />
  553. public void SetShuffleMode(GroupShuffleMode mode)
  554. {
  555. PlayQueue.SetShuffleMode(mode);
  556. }
  557. /// <inheritdoc />
  558. public PlayQueueUpdate GetPlayQueueUpdate(PlayQueueUpdateReason reason)
  559. {
  560. var startPositionTicks = PositionTicks;
  561. var isPlaying = _state.Type.Equals(GroupStateType.Playing);
  562. if (isPlaying)
  563. {
  564. var currentTime = DateTime.UtcNow;
  565. var elapsedTime = currentTime - LastActivity;
  566. // Elapsed time is negative if event happens
  567. // during the delay added to account for latency.
  568. // In this phase clients haven't started the playback yet.
  569. // In other words, LastActivity is in the future,
  570. // when playback unpause is supposed to happen.
  571. // Adjust ticks only if playback actually started.
  572. startPositionTicks += Math.Max(elapsedTime.Ticks, 0);
  573. }
  574. return new PlayQueueUpdate(
  575. reason,
  576. PlayQueue.LastChange,
  577. PlayQueue.GetPlaylist(),
  578. PlayQueue.PlayingItemIndex,
  579. startPositionTicks,
  580. isPlaying,
  581. PlayQueue.ShuffleMode,
  582. PlayQueue.RepeatMode);
  583. }
  584. }
  585. }