When streaming start from current location

This commit is contained in:
Duncan Tourolle 2025-12-15 20:43:49 +01:00
parent 609a16f468
commit 1b7b836b3e

View File

@ -172,8 +172,15 @@ public class LmsSessionController : ISessionController, IDisposable
var itemId = _playlist[index]; var itemId = _playlist[index];
_playlistIndex = index; _playlistIndex = index;
var streamUrl = BuildStreamUrl(itemId); // Build stream URL with start position - LMS can't seek on HTTP streams,
_logger.LogInformation("Playing item {Index}/{Total}: {Url}", index + 1, _playlist.Length, streamUrl); // 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); await _lmsClient.PlayUrlAsync(_player.MacAddress, streamUrl).ConfigureAwait(false);
@ -181,18 +188,15 @@ public class LmsSessionController : ISessionController, IDisposable
CurrentItemId = itemId; CurrentItemId = itemId;
IsPlaying = true; IsPlaying = true;
IsPaused = false; 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 // Look up the item for duration info
_currentItem = _libraryManager.GetItemById(itemId); _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 // Report playback start to Jellyfin
await ReportPlaybackStartAsync(itemId, startPositionTicks).ConfigureAwait(false); await ReportPlaybackStartAsync(itemId, startPositionTicks).ConfigureAwait(false);