Streaming Bug Fixes

This commit is contained in:
daniel-c-harvey
2025-12-06 06:41:32 -05:00
parent 605fc94fbb
commit 2baf0575bc
17 changed files with 1510 additions and 1054 deletions
@@ -42,7 +42,7 @@ else
Step="0.1"
Value="@CurrentTime"
ValueChanged="@OnSeek"
Disabled="!IsLoaded"/>
Disabled="@(!IsLoaded || IsStreamingMode)"/>
</div>
<div class="volume-right">
@@ -77,7 +77,7 @@ else
Step="0.1"
Value="@CurrentTime"
ValueChanged="@OnSeek"
Disabled="!IsLoaded"/>
Disabled="@(!IsLoaded || IsStreamingMode)"/>
</div>
@* Control Buttons - positioned absolutely like original *@
@@ -13,6 +13,7 @@ public partial class AudioPlayerBar : ComponentBase
private bool IsLoaded => PlayerService.IsLoaded;
private bool IsLoading => PlayerService.IsLoading;
private bool IsStreaming => PlayerService.CanStartStreaming;
private bool IsStreamingMode => PlayerService.IsStreamingMode;
private bool IsPlaying => PlayerService.IsPlaying;
private bool IsPaused => PlayerService.IsPaused;
private double CurrentTime => PlayerService.CurrentTime;
@@ -26,6 +27,21 @@ public partial class AudioPlayerBar : ComponentBase
await base.OnInitializedAsync();
// Set up EventCallback for track selection
PlayerService.OnTrackSelected = new EventCallback(this, Expand);
// Store the original OnStateChanged callback set by the provider
var originalOnStateChanged = PlayerService.OnStateChanged;
// Set up a wrapper that calls both the original callback and our StateHasChanged
PlayerService.OnStateChanged = new EventCallback(this, async () =>
{
// Invoke the original callback (AudioPlayerProvider's StateHasChanged)
if (originalOnStateChanged.HasValue)
{
await originalOnStateChanged.Value.InvokeAsync();
}
// Also trigger our own re-render
await InvokeAsync(StateHasChanged);
});
}
private async Task Expand()
@@ -19,9 +19,10 @@ public partial class AudioPlayerProvider : ComponentBase
{
// Create the service immediately (but don't initialize yet)
_audioPlayerService = new StreamingAudioPlayerService(AudioInterop, TrackMediaClient, Logger);
// Set up EventCallback to properly marshal UI updates back to UI thread
_audioPlayerService.OnStateChanged = new EventCallback(this, StateHasChanged);
// Use InvokeAsync to ensure proper Blazor render cycle triggering
_audioPlayerService.OnStateChanged = new EventCallback(this, () => InvokeAsync(StateHasChanged));
// OnTrackSelected will be set by individual child components that need it
}