fix: enable player controls on load, clear track selection on stop and end-of-track

Add StateChanged multicast event to IPlayerService so AudioPlayerBar and TracksView
re-render themselves without relying on the IsFixed cascade re-render path. Clear
_selectedTrack in TracksView when IsLoaded drops (stop, unload, end-of-track). Set
IsLoaded=false in OnPlaybackEndCallback so end-of-track triggers the same clear path.
Add JS-module readiness probe in AudioInteropService; delete dead TS and buffered C#
path; consolidate GetPlayIcon/FormatTime helpers; fix misleading minimize dock icon.
This commit is contained in:
daniel-c-harvey
2026-06-03 14:30:15 -04:00
parent b8a51e4656
commit 7d49c64a5d
9 changed files with 135 additions and 443 deletions
@@ -6,21 +6,51 @@ using Models.Common;
namespace DeepDrftPublic.Client.Pages;
public partial class TracksView : ComponentBase
public partial class TracksView : ComponentBase, IDisposable
{
[Inject] public required TracksViewModel ViewModel { get; set; }
[CascadingParameter] public required IStreamingPlayerService PlayerService { get; set; }
private TrackDto? _selectedTrack = null;
private int _clickCount = 0;
private string _lifecycleStatus = "Not initialized";
private IStreamingPlayerService? _subscribedService;
protected override async Task OnInitializedAsync()
{
_lifecycleStatus = "OnInitializedAsync called";
await SetPage(1);
}
protected override void OnParametersSet()
{
// The Stop/Close buttons on the player bar reset the player directly,
// bypassing PlayTrack — so the gallery's selection must follow player
// state rather than only its own clicks. Subscribe to the multicast
// side-channel (the cascade is IsFixed, so provider re-renders don't
// reach us) and clear the highlight when nothing is loaded.
if (PlayerService != null && !ReferenceEquals(PlayerService, _subscribedService))
{
if (_subscribedService != null)
_subscribedService.StateChanged -= OnPlayerStateChanged;
PlayerService.StateChanged += OnPlayerStateChanged;
_subscribedService = PlayerService;
}
}
private void OnPlayerStateChanged()
{
// Sync the gallery selection to the player. When the player is no longer
// loaded (stopped/closed/ended) drop the highlight; guard against a
// redundant re-render when nothing actually changed.
if (!PlayerService.IsLoaded && _selectedTrack != null)
{
_selectedTrack = null;
InvokeAsync(StateHasChanged);
}
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
@@ -62,4 +92,13 @@ public partial class TracksView : ComponentBase
_selectedTrack = track;
}
public void Dispose()
{
if (_subscribedService != null)
{
_subscribedService.StateChanged -= OnPlayerStateChanged;
_subscribedService = null;
}
}
}