Code: Select all
Parent.razor
Code: Select all
@inject IDialogService DialogService
private readonly DialogOptions _dialogOptions = new() { MaxWidth = MaxWidth.Medium, FullWidth = true, CloseButton = true, CloseOnEscapeKey = true, NoHeader = false };
private async Task OpenDialogViewAsync(int id, string name)
{
JsonDocument text = await GetText(textId);
var parameters = new DialogParameters
{
{ "name", name},
{ "jsonContent", text},
{ "id", transcriptionId}
};
var completeTitle = $"File: {name}";
var dialog = await DialogService.ShowAsync(completeTitle, parameters, _dialogOptions);
var result = await dialog.Result;
}
< /code>
TextViewDialog.razor
@implements IDisposable
protected override async Task OnInitializedAsync()
{
_loading = true;
await PerformSearch();
_loading = false;
await LoadAudioUrl();
StateHasChanged();
}
private async Task LoadAudioUrl()
{
try
{
audioBytes = await getAudio(id);
if (audioBytes != null && audioBytes.Length > 0)
{
audioUrl = $"data:audio/mpeg;base64,{Convert.ToBase64String(audioBytes)}";
Logger.LogInformation("Audio URL set successfully.");
}
else
{
Logger.LogWarning("Audio file is empty or null.");
}
}
catch (Exception ex)
{
Logger.LogError(ex, "Error loading audio URL");
Snackbar.Add($"Error loading audio URL: {ex.Message}", MudBlazor.Severity.Error);
}
StateHasChanged();
}
private void Close()
{
Dispose();
MudDialog.Close(DialogResult.Ok(true));
}
< /code>
I have tried implementing IDisposable and clearing the variables defined in that dialog:
public void Dispose()
{
JSRuntime.InvokeVoidAsync("disposeAudioPlayer");
JsonContent = null;
TextContent = null;
Array.Clear(audioBytes, 0, audioBytes.Length);
}
< /code>
But that had no effect. I read that MudBlazor calls the Dispose() method once the dialog is closed but I don't seem to be able to understand what the root cause of the issue is or if I am setting something up wrong.