From 1b7b836b3e370f780130e8325e9b4a63a2102b1e Mon Sep 17 00:00:00 2001 From: Duncan Tourolle Date: Mon, 15 Dec 2025 20:43:49 +0100 Subject: [PATCH] When streaming start from current location --- .../Services/LmsSessionController.cs | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/Jellyfin.Plugin.JellyLMS/Services/LmsSessionController.cs b/Jellyfin.Plugin.JellyLMS/Services/LmsSessionController.cs index 9d8b31c..2392328 100644 --- a/Jellyfin.Plugin.JellyLMS/Services/LmsSessionController.cs +++ b/Jellyfin.Plugin.JellyLMS/Services/LmsSessionController.cs @@ -172,8 +172,15 @@ public class LmsSessionController : ISessionController, IDisposable var itemId = _playlist[index]; _playlistIndex = index; - var streamUrl = BuildStreamUrl(itemId); - _logger.LogInformation("Playing item {Index}/{Total}: {Url}", index + 1, _playlist.Length, streamUrl); + // Build stream URL with start position - LMS can't seek on HTTP streams, + // so we need to use Jellyfin's startTimeTicks parameter for transcoding + var streamUrl = BuildStreamUrlWithPosition(itemId, startPositionTicks); + _logger.LogInformation( + "Playing item {Index}/{Total} from position {Position}s: {Url}", + index + 1, + _playlist.Length, + startPositionTicks / TimeSpan.TicksPerSecond, + streamUrl); await _lmsClient.PlayUrlAsync(_player.MacAddress, streamUrl).ConfigureAwait(false); @@ -181,18 +188,15 @@ public class LmsSessionController : ISessionController, IDisposable CurrentItemId = itemId; IsPlaying = true; IsPaused = false; - _seekOffsetTicks = 0; // Reset seek offset when starting a new track + + // Track the seek offset so we report the correct position + // When starting from a position, the transcoded stream starts at 0, + // but we need to report the actual track position + _seekOffsetTicks = startPositionTicks; // Look up the item for duration info _currentItem = _libraryManager.GetItemById(itemId); - // Seek to start position if specified - if (startPositionTicks > 0) - { - var positionSeconds = startPositionTicks / TimeSpan.TicksPerSecond; - await _lmsClient.SeekAsync(_player.MacAddress, positionSeconds).ConfigureAwait(false); - } - // Report playback start to Jellyfin await ReportPlaybackStartAsync(itemId, startPositionTicks).ConfigureAwait(false);