track progress
This commit is contained in:
@@ -39,8 +39,23 @@ public class LmsSessionController : ISessionController
|
||||
_session = session;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the currently playing item ID.
|
||||
/// </summary>
|
||||
public Guid? CurrentItemId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether playback is currently active.
|
||||
/// </summary>
|
||||
public bool IsPlaying { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether playback is paused.
|
||||
/// </summary>
|
||||
public bool IsPaused { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsSessionActive => _player.IsConnected && _player.IsPoweredOn;
|
||||
public bool IsSessionActive => _player.IsConnected;
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool SupportsMediaControl => true;
|
||||
@@ -57,10 +72,11 @@ public class LmsSessionController : ISessionController
|
||||
T data,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
_logger.LogDebug(
|
||||
"LMS Session Controller received message {MessageType} for player {PlayerName}",
|
||||
_logger.LogInformation(
|
||||
"LMS Session Controller received message {MessageType} for player {PlayerName} ({Mac})",
|
||||
name,
|
||||
_player.Name);
|
||||
_player.Name,
|
||||
_player.MacAddress);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -118,6 +134,11 @@ public class LmsSessionController : ISessionController
|
||||
_logger.LogInformation("Playing stream URL: {Url}", streamUrl);
|
||||
await _lmsClient.PlayUrlAsync(_player.MacAddress, streamUrl).ConfigureAwait(false);
|
||||
|
||||
// Track current playback state
|
||||
CurrentItemId = itemId;
|
||||
IsPlaying = true;
|
||||
IsPaused = false;
|
||||
|
||||
// Seek to start position if specified
|
||||
if (playRequest.StartPositionTicks.HasValue && playRequest.StartPositionTicks.Value > 0)
|
||||
{
|
||||
@@ -135,29 +156,60 @@ public class LmsSessionController : ISessionController
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogDebug(
|
||||
"Playstate command {Command} for player {PlayerName}",
|
||||
_logger.LogInformation(
|
||||
"Playstate command {Command} for player {PlayerName} ({Mac})",
|
||||
playstateRequest.Command,
|
||||
_player.Name);
|
||||
_player.Name,
|
||||
_player.MacAddress);
|
||||
|
||||
switch (playstateRequest.Command)
|
||||
{
|
||||
case PlaystateCommand.Stop:
|
||||
await _lmsClient.StopAsync(_player.MacAddress).ConfigureAwait(false);
|
||||
var stopResult = await _lmsClient.StopAsync(_player.MacAddress).ConfigureAwait(false);
|
||||
_logger.LogInformation("Stop command result: {Result}", stopResult);
|
||||
IsPlaying = false;
|
||||
IsPaused = false;
|
||||
CurrentItemId = null;
|
||||
break;
|
||||
|
||||
case PlaystateCommand.Pause:
|
||||
await _lmsClient.PauseAsync(_player.MacAddress).ConfigureAwait(false);
|
||||
var pauseResult = await _lmsClient.PauseAsync(_player.MacAddress).ConfigureAwait(false);
|
||||
_logger.LogInformation("Pause command result: {Result}", pauseResult);
|
||||
IsPaused = true;
|
||||
break;
|
||||
|
||||
case PlaystateCommand.Unpause:
|
||||
await _lmsClient.PlayAsync(_player.MacAddress).ConfigureAwait(false);
|
||||
var playResult = await _lmsClient.PlayAsync(_player.MacAddress).ConfigureAwait(false);
|
||||
_logger.LogInformation("Unpause/Play command result: {Result}", playResult);
|
||||
IsPaused = false;
|
||||
break;
|
||||
|
||||
case PlaystateCommand.PlayPause:
|
||||
// Toggle play/pause - check current state first
|
||||
var currentState = await _lmsClient.GetPlayerStatusAsync(_player.MacAddress).ConfigureAwait(false);
|
||||
if (currentState?.Mode == "play")
|
||||
{
|
||||
var togglePauseResult = await _lmsClient.PauseAsync(_player.MacAddress).ConfigureAwait(false);
|
||||
_logger.LogInformation("PlayPause toggle (pause) result: {Result}", togglePauseResult);
|
||||
IsPaused = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
var togglePlayResult = await _lmsClient.PlayAsync(_player.MacAddress).ConfigureAwait(false);
|
||||
_logger.LogInformation("PlayPause toggle (play) result: {Result}", togglePlayResult);
|
||||
IsPaused = false;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case PlaystateCommand.Seek:
|
||||
if (playstateRequest.SeekPositionTicks.HasValue)
|
||||
{
|
||||
var positionSeconds = playstateRequest.SeekPositionTicks.Value / TimeSpan.TicksPerSecond;
|
||||
_logger.LogInformation(
|
||||
"Seeking player {PlayerName} to {Seconds} seconds",
|
||||
_player.Name,
|
||||
positionSeconds);
|
||||
await _lmsClient.SeekAsync(_player.MacAddress, positionSeconds).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user