This commit is contained in:
2026-02-02 19:06:33 -05:00
parent 2ffb769a6f
commit ab36a43892

View File

@@ -1785,28 +1785,6 @@ public class JellyfinController : ControllerBase
_logger.LogInformation("📻 Playback START reported");
// Extract device info and ensure session exists
var (deviceId, client, device, version) = ExtractDeviceInfo(Request.Headers);
if (!string.IsNullOrEmpty(deviceId))
{
var sessionCreated = await _sessionManager.EnsureSessionAsync(deviceId, client ?? "Unknown", device ?? "Unknown", version ?? "1.0", Request.Headers);
if (sessionCreated)
{
_logger.LogInformation("✓ Session ensured for device {DeviceId}", deviceId);
// Give Jellyfin a moment to process the session creation
await Task.Delay(100);
}
else
{
_logger.LogWarning("⚠️ Failed to ensure session for device {DeviceId}", deviceId);
}
}
else
{
_logger.LogWarning("⚠️ No device ID found in headers - session cannot be created");
}
// Parse the body to check if it's an external track
var doc = JsonDocument.Parse(body);
string? itemId = null;
@@ -1839,11 +1817,10 @@ public class JellyfinController : ControllerBase
itemName ?? "Unknown", itemId);
}
// For local tracks, forward to Jellyfin with client auth
// For local tracks, forward playback start to Jellyfin FIRST
_logger.LogInformation("Forwarding playback start to Jellyfin...");
// Fetch full item details to include in playback report
// This makes the session show up properly in Jellyfin dashboard with "Now Playing"
try
{
var (itemResult, itemStatus) = await _proxyService.GetJsonAsync($"Items/{itemId}", null, Request.Headers);
@@ -1868,6 +1845,17 @@ public class JellyfinController : ControllerBase
if (statusCode == 204 || statusCode == 200)
{
_logger.LogInformation("✓ Playback start forwarded to Jellyfin ({StatusCode})", statusCode);
// NOW ensure session exists with capabilities (after playback is reported)
var (deviceId, client, device, version) = ExtractDeviceInfo(Request.Headers);
if (!string.IsNullOrEmpty(deviceId))
{
var sessionCreated = await _sessionManager.EnsureSessionAsync(deviceId, client ?? "Unknown", device ?? "Unknown", version ?? "1.0", Request.Headers);
if (sessionCreated)
{
_logger.LogInformation("✓ Session ensured for device {DeviceId} after playback start", deviceId);
}
}
}
else
{