diff --git a/Jellyfin.Plugin.JellyLMS/Configuration/PluginConfiguration.cs b/Jellyfin.Plugin.JellyLMS/Configuration/PluginConfiguration.cs
index 228d981..564fca6 100644
--- a/Jellyfin.Plugin.JellyLMS/Configuration/PluginConfiguration.cs
+++ b/Jellyfin.Plugin.JellyLMS/Configuration/PluginConfiguration.cs
@@ -62,4 +62,24 @@ public class PluginConfiguration : BasePluginConfiguration
/// Gets or sets the Jellyfin API key for authenticating stream requests from LMS.
///
public string JellyfinApiKey { get; set; } = string.Empty;
+
+ ///
If LMS and Jellyfin share the same storage (e.g., NAS), enable direct file access for native seeking support. This provides smooth seeking without audio restart.
+ +Select players to sync together for multi-room audio. Synced players play in perfect sync.
@@ -418,6 +445,9 @@ document.querySelector('#ConnectionTimeoutSeconds').value = config.ConnectionTimeoutSeconds || 10; document.querySelector('#EnableAutoSync').checked = config.EnableAutoSync !== false; document.querySelector('#DefaultPlayerMac').value = config.DefaultPlayerMac || ''; + document.querySelector('#UseDirectFilePath').checked = config.UseDirectFilePath || false; + document.querySelector('#JellyfinMediaPath').value = config.JellyfinMediaPath || ''; + document.querySelector('#LmsMediaPath').value = config.LmsMediaPath || ''; Dashboard.hideLoadingMsg(); loadPlayers(); @@ -460,6 +490,9 @@ config.ConnectionTimeoutSeconds = parseInt(document.querySelector('#ConnectionTimeoutSeconds').value) || 10; config.EnableAutoSync = document.querySelector('#EnableAutoSync').checked; config.DefaultPlayerMac = document.querySelector('#DefaultPlayerMac').value; + config.UseDirectFilePath = document.querySelector('#UseDirectFilePath').checked; + config.JellyfinMediaPath = document.querySelector('#JellyfinMediaPath').value; + config.LmsMediaPath = document.querySelector('#LmsMediaPath').value; ApiClient.updatePluginConfiguration(JellyLmsConfig.pluginUniqueId, config).then(function (result) { Dashboard.processPluginConfigurationUpdateResult(result); }); diff --git a/Jellyfin.Plugin.JellyLMS/Services/LmsSessionController.cs b/Jellyfin.Plugin.JellyLMS/Services/LmsSessionController.cs index 2392328..708df61 100644 --- a/Jellyfin.Plugin.JellyLMS/Services/LmsSessionController.cs +++ b/Jellyfin.Plugin.JellyLMS/Services/LmsSessionController.cs @@ -172,14 +172,17 @@ public class LmsSessionController : ISessionController, IDisposable var itemId = _playlist[index]; _playlistIndex = index; - // 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); + // Look up the item first - we need it for file path if using direct mode + _currentItem = _libraryManager.GetItemById(itemId); + + // Build stream URL/path with start position + var (streamUrl, useDirectPath) = BuildPlaybackUrl(itemId, startPositionTicks); _logger.LogInformation( - "Playing item {Index}/{Total} from position {Position}s: {Url}", + "Playing item {Index}/{Total} from position {Position}s (direct={Direct}): {Url}", index + 1, _playlist.Length, startPositionTicks / TimeSpan.TicksPerSecond, + useDirectPath, streamUrl); await _lmsClient.PlayUrlAsync(_player.MacAddress, streamUrl).ConfigureAwait(false); @@ -190,12 +193,9 @@ public class LmsSessionController : ISessionController, IDisposable IsPaused = false; // 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); + // When using direct file paths, LMS handles seeking natively so no offset needed + // When using HTTP streaming with startTimeTicks, the stream starts at 0 but we need to report actual position + _seekOffsetTicks = useDirectPath ? 0 : startPositionTicks; // Report playback start to Jellyfin await ReportPlaybackStartAsync(itemId, startPositionTicks).ConfigureAwait(false); @@ -419,21 +419,42 @@ public class LmsSessionController : ISessionController, IDisposable if (playstateRequest.SeekPositionTicks.HasValue && CurrentItemId.HasValue) { var positionTicks = playstateRequest.SeekPositionTicks.Value; + var positionSeconds = positionTicks / TimeSpan.TicksPerSecond; - // For HTTP streams, LMS can't seek directly - we need to restart with startTimeTicks - // Build a new URL with the seek position and restart playback - var streamUrl = BuildStreamUrlWithPosition(CurrentItemId.Value, positionTicks); - _logger.LogInformation( - "Seeking by restarting stream at position {Seconds}s: {Url}", - positionTicks / TimeSpan.TicksPerSecond, - streamUrl); + // Check if we're using direct file path mode - if so, LMS can seek natively + var config = Plugin.Instance?.Configuration; + var canSeekNatively = config?.UseDirectFilePath == true + && !string.IsNullOrEmpty(config.JellyfinMediaPath) + && !string.IsNullOrEmpty(config.LmsMediaPath) + && _currentItem?.Path != null + && _currentItem.Path.StartsWith(config.JellyfinMediaPath, StringComparison.OrdinalIgnoreCase); - await _lmsClient.PlayUrlAsync(_player.MacAddress, streamUrl).ConfigureAwait(false); + if (canSeekNatively) + { + // Use native LMS seeking - much smoother! + _logger.LogInformation("Seeking natively to {Seconds}s using LMS time command", positionSeconds); + await _lmsClient.SeekAsync(_player.MacAddress, positionSeconds).ConfigureAwait(false); + // No seek offset needed - LMS handles position tracking natively + _seekOffsetTicks = 0; + } + else + { + // For HTTP streams, LMS can't seek directly - we need to restart with startTimeTicks + // Build a new URL with the seek position and restart playback + var streamUrl = BuildStreamUrlWithPosition(CurrentItemId.Value, positionTicks); + _logger.LogInformation( + "Seeking by restarting stream at position {Seconds}s: {Url}", + positionSeconds, + streamUrl); - // Track the seek offset so we report the correct position - // The transcoded stream starts at 0, but we need to report the actual track position - _seekOffsetTicks = positionTicks; - _logger.LogInformation("Set seek offset to {Ticks} ticks ({Seconds}s)", positionTicks, positionTicks / TimeSpan.TicksPerSecond); + await _lmsClient.PlayUrlAsync(_player.MacAddress, streamUrl).ConfigureAwait(false); + + // Track the seek offset so we report the correct position + // The transcoded stream starts at 0, but we need to report the actual track position + _seekOffsetTicks = positionTicks; + } + + _logger.LogInformation("Seek offset is now {Ticks} ticks ({Seconds}s)", _seekOffsetTicks, _seekOffsetTicks / TimeSpan.TicksPerSecond); } else { @@ -536,6 +557,59 @@ public class LmsSessionController : ISessionController, IDisposable } } + ///