From fe5d83a94214cb34d865c6d7ab138ea96ba5f325 Mon Sep 17 00:00:00 2001 From: Kilian von Pflugk Date: Sat, 18 May 2024 14:20:10 +0200 Subject: [PATCH] Revert "AutoSkipCredits don't seek use NextTrack" This reverts commit bae53323feb0a5894f9c52a13218b9b293eea0bb. --- .../AutoSkipCredits.cs | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/AutoSkipCredits.cs b/ConfusedPolarBear.Plugin.IntroSkipper/AutoSkipCredits.cs index 1ebb87c..07155e3 100644 --- a/ConfusedPolarBear.Plugin.IntroSkipper/AutoSkipCredits.cs +++ b/ConfusedPolarBear.Plugin.IntroSkipper/AutoSkipCredits.cs @@ -28,7 +28,7 @@ public class AutoSkipCredits : IHostedService, IDisposable private IUserDataManager _userDataManager; private ISessionManager _sessionManager; private Timer _playbackTimer = new(1000); - private Dictionary _sentNextCommand; + private Dictionary _sentSeekCommand; /// /// Initializes a new instance of the class. @@ -44,7 +44,7 @@ public class AutoSkipCredits : IHostedService, IDisposable _userDataManager = userDataManager; _sessionManager = sessionManager; _logger = logger; - _sentNextCommand = new Dictionary(); + _sentSeekCommand = new Dictionary(); } private void AutoSkipCreditChanged(object? sender, BasePluginConfiguration e) @@ -103,8 +103,8 @@ public class AutoSkipCredits : IHostedService, IDisposable { var device = session.DeviceId; - _logger.LogDebug("Resetting next command state for session {Session}", device); - _sentNextCommand[device] = newState; + _logger.LogDebug("Resetting seek command state for session {Session}", device); + _sentSeekCommand[device] = newState; } } @@ -119,7 +119,7 @@ public class AutoSkipCredits : IHostedService, IDisposable // Don't send the seek command more than once in the same session. lock (_sentSeekCommandLock) { - if (_sentNextCommand.TryGetValue(deviceId, out var sent) && sent) + if (_sentSeekCommand.TryGetValue(deviceId, out var sent) && sent) { _logger.LogTrace("Already sent seek command for session {Session}", deviceId); continue; @@ -127,7 +127,7 @@ public class AutoSkipCredits : IHostedService, IDisposable } // Assert that credits were detected for this item. - if (!Plugin.Instance!.Credits.TryGetValue(itemId, out var credit)) + if (!Plugin.Instance!.Credits.TryGetValue(itemId, out var credit) || !credit.Valid) { continue; } @@ -141,7 +141,7 @@ public class AutoSkipCredits : IHostedService, IDisposable adjustedStart, credit.IntroEnd); - if (position < adjustedStart) + if (position < adjustedStart || position > credit.IntroEnd) { continue; } @@ -162,7 +162,7 @@ public class AutoSkipCredits : IHostedService, IDisposable CancellationToken.None); } - _logger.LogDebug("Sending next track command to {Session}", deviceId); + _logger.LogDebug("Sending seek command to {Session}", deviceId); var creditEnd = (long)credit.IntroEnd; @@ -171,16 +171,17 @@ public class AutoSkipCredits : IHostedService, IDisposable session.Id, new PlaystateRequest { - Command = PlaystateCommand.NextTrack, + Command = PlaystateCommand.Seek, ControllingUserId = session.UserId.ToString(), + SeekPositionTicks = creditEnd * TimeSpan.TicksPerSecond, }, CancellationToken.None); // Flag that we've sent the seek command so that it's not sent repeatedly lock (_sentSeekCommandLock) { - _logger.LogTrace("Setting next track command state for session {Session}", deviceId); - _sentNextCommand[deviceId] = true; + _logger.LogTrace("Setting seek command state for session {Session}", deviceId); + _sentSeekCommand[deviceId] = true; } } }