diff --git a/samples/KristofferStrube.Blazor.MediaStreamRecording.WasmExample/Pages/Home.razor b/samples/KristofferStrube.Blazor.MediaStreamRecording.WasmExample/Pages/Home.razor index 06b54fc..be6fcff 100644 --- a/samples/KristofferStrube.Blazor.MediaStreamRecording.WasmExample/Pages/Home.razor +++ b/samples/KristofferStrube.Blazor.MediaStreamRecording.WasmExample/Pages/Home.razor @@ -5,7 +5,8 @@ @using KristofferStrube.Blazor.WebAudio @using KristofferStrube.Blazor.WebIDL.Exceptions @inject IJSRuntime JSRuntime -@inject IMediaDevicesService MediaDevicesService; +@inject IMediaDevicesService MediaDevicesService +@inject IURLService URLService @implements IAsyncDisposable Blazor.MediaStreamRecording - Audio Recording @@ -72,6 +73,8 @@ else if (audioSourceNode is null) +
+ Download } else { @@ -84,6 +87,9 @@ else +
+ Download +
} diff --git a/samples/KristofferStrube.Blazor.MediaStreamRecording.WasmExample/Pages/Home.razor.cs b/samples/KristofferStrube.Blazor.MediaStreamRecording.WasmExample/Pages/Home.razor.cs index 9fab548..a1b3c0f 100644 --- a/samples/KristofferStrube.Blazor.MediaStreamRecording.WasmExample/Pages/Home.razor.cs +++ b/samples/KristofferStrube.Blazor.MediaStreamRecording.WasmExample/Pages/Home.razor.cs @@ -10,7 +10,7 @@ public partial class Home { private string? error; private MediaStream? mediaStream; - private readonly List<(string label, string id)> audioOptions = new(); + private readonly List<(string label, string id)> audioOptions = []; private string? selectedAudioSource; private MediaStreamAudioSourceNode? liveSourceNoce; private AnalyserNode? liveAnalyzer; @@ -18,13 +18,14 @@ public partial class Home private MediaRecorder? recorder; private EventListener? dataAvailableEventListener; private Blob? combinedBlob; + private string combinedBlobURL = ""; private AudioBuffer? audioBuffer; - private readonly List blobsRecorded = new(); + private readonly List blobsRecorded = []; private AudioContext? context; private AudioBufferSourceNode? audioSourceNode; private AnalyserNode? bufferAnalyzer; - private AmplitudePlot plot; + private AmplitudePlot plot = default!; private async Task OpenAudioStream() { @@ -110,6 +111,7 @@ private async Task StopRecording() await recorder.DisposeAsync(); combinedBlob = await Blob.CreateAsync(JSRuntime, [.. blobsRecorded], new() { Type = await blobsRecorded.First().GetTypeAsync() }); + combinedBlobURL = await URLService.CreateObjectURLAsync(combinedBlob); foreach (Blob blob in blobsRecorded) { @@ -201,6 +203,9 @@ private async Task StopPlayingRecording() } if (combinedBlob is not null) await combinedBlob.JSReference.DisposeAsync(); + + if (combinedBlobURL is not "") + await URLService.RevokeObjectURLAsync(combinedBlobURL); } public async ValueTask DisposeAsync() diff --git a/samples/KristofferStrube.Blazor.MediaStreamRecording.WasmExample/Program.cs b/samples/KristofferStrube.Blazor.MediaStreamRecording.WasmExample/Program.cs index 398b147..e50d12d 100644 --- a/samples/KristofferStrube.Blazor.MediaStreamRecording.WasmExample/Program.cs +++ b/samples/KristofferStrube.Blazor.MediaStreamRecording.WasmExample/Program.cs @@ -1,3 +1,4 @@ +using KristofferStrube.Blazor.FileAPI; using KristofferStrube.Blazor.MediaCaptureStreams; using KristofferStrube.Blazor.MediaStreamRecording.WasmExample; using KristofferStrube.Blazor.WebIDL; @@ -13,6 +14,8 @@ // Adding IMediaDevicesService to service collection. builder.Services.AddMediaDevicesService(); +builder.Services.AddURLService(); + WebAssemblyHost app = builder.Build(); // For Blazor WASM you need to call this to make Error Handling JS Interop.