KristofferStrube.Blazor.MediaStreamRecording 0.1.0-alpha.1

Prefix Reserved
This is a prerelease version of KristofferStrube.Blazor.MediaStreamRecording.
dotnet add package KristofferStrube.Blazor.MediaStreamRecording --version 0.1.0-alpha.1                
NuGet\Install-Package KristofferStrube.Blazor.MediaStreamRecording -Version 0.1.0-alpha.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="KristofferStrube.Blazor.MediaStreamRecording" Version="0.1.0-alpha.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add KristofferStrube.Blazor.MediaStreamRecording --version 0.1.0-alpha.1                
#r "nuget: KristofferStrube.Blazor.MediaStreamRecording, 0.1.0-alpha.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install KristofferStrube.Blazor.MediaStreamRecording as a Cake Addin
#addin nuget:?package=KristofferStrube.Blazor.MediaStreamRecording&version=0.1.0-alpha.1&prerelease

// Install KristofferStrube.Blazor.MediaStreamRecording as a Cake Tool
#tool nuget:?package=KristofferStrube.Blazor.MediaStreamRecording&version=0.1.0-alpha.1&prerelease                

License: MIT GitHub issues GitHub forks GitHub stars NuGet Downloads (official NuGet)

Blazor.MediaStreamRecording

A Blazor wrapper for the MediaStream Recording browser API.

This Web API makes it easy to record sound from a MediaStream. It additionally makes it possible to query which encodings the current platform has available for recording. This project implements a wrapper around the API for Blazor so that we can easily and safely record sound in the browser.

Demo

The sample project can be demoed at https://kristofferstrube.github.io/Blazor.MediaStreamRecording/

On each page, you can find the corresponding code for the example in the top right corner.

On the API Coverage Status page, you can see how much of the WebIDL specs this wrapper has covered.

Getting Started

Prerequisites

You need to install .NET 7.0 or newer to use the library.

Download .NET 7

Installation

You can install the package via NuGet with the Package Manager in your IDE or alternatively using the command line:

dotnet add package KristofferStrube.Blazor.MediaStreamRecording

Usage

The package can be used in Blazor WebAssembly and Blazor Server projects.

Import

You need to reference the package in order to use it in your pages. This can be done in _Import.razor by adding the following.

@using KristofferStrube.Blazor.MediaStreamRecording

Recording MediaStream

The primary purpose of the API is to record some MediaStream. You can get a MediaStream using the Blazor.MediaCaptureStreams library. After this you can use the following minimal sample for recording a MediaStream.

// List to collect each recording part.
List<Blob> blobsRecorded = new();

// Create new MediaRecorder from some existing MediaStream.
await using MediaRecorder recorder = await MediaRecorder.CreateAsync(JSRuntime, mediaStream);

// Add event listener for when each data part is available.
await using var dataAvailableEventListener =
    await EventListener<BlobEvent>.CreateAsync(JSRuntime, async (BlobEvent e) =>
    {
        Blob blob = await e.GetDataAsync();
        blobsRecorded.Add(blob);
    });
await recorder.AddOnDataAvailableEventListenerAsync(dataAvailableEventListener);

// Starts Recording
await recorder.StartAsync();

// Records for 5 seconds.
await Task.Delay(5000);

// Stops recording
await recorder.StopAsync();

// Combines and collects the total audio data.
await using Blob combinedBlob = await Blob.CreateAsync(JSRuntime, [.. blobsRecorded]);
byte[] audioData = await combinedBlob.ArrayBufferAsync();

// Dispose of blob parts created while recording.
foreach (Blob blob in blobsRecorded)
    await blob.DisposeAsync();

The library uses the following other packages to support its features:

This repository was built with inspiration and help from the following series of articles:

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on KristofferStrube.Blazor.MediaStreamRecording:

Repository Stars
KristofferStrube/Blazor.WebAudio
A Blazor wrapper for the Web Audio browser API.
Version Downloads Last updated
0.1.0-alpha.1 82 8/26/2024