Gondwana.Audio.Browser 2.2.4

dotnet add package Gondwana.Audio.Browser --version 2.2.4
                    
NuGet\Install-Package Gondwana.Audio.Browser -Version 2.2.4
                    
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="Gondwana.Audio.Browser" Version="2.2.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Gondwana.Audio.Browser" Version="2.2.4" />
                    
Directory.Packages.props
<PackageReference Include="Gondwana.Audio.Browser" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Gondwana.Audio.Browser --version 2.2.4
                    
#r "nuget: Gondwana.Audio.Browser, 2.2.4"
                    
#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.
#:package Gondwana.Audio.Browser@2.2.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Gondwana.Audio.Browser&version=2.2.4
                    
Install as a Cake Addin
#tool nuget:?package=Gondwana.Audio.Browser&version=2.2.4
                    
Install as a Cake Tool

Gondwana.Audio.Browser

Gondwana.Audio.Browser adds HTML5 Audio API playback support to the Gondwana Game Engine for browser/WASM targets built with net8.0-browser.

It uses .NET 8's native JavaScript interop ([JSImport]) to route all audio operations through a lightweight JavaScript ES module, bypassing the desktop NAudio pipeline that is unavailable in WebAssembly.

Features

  • Plays .mp3, .wav, .ogg, and any other format supported by the host browser
  • Volume and loop control
  • Play, pause, stop, and seek
  • Zero external .NET dependencies — only System.Runtime.InteropServices.JavaScript
  • Ships the gondwana-audio.js module as a NuGet content file (automatically placed in wwwroot/)

Installation

dotnet add package Gondwana.Audio.Browser

The NuGet package automatically copies gondwana-audio.js into your project's wwwroot/ folder so that it is included in the WASM AppBundle on publish.

Setup

1. Import the JS module before Avalonia starts

In Program.Browser.cs:

using System.Runtime.InteropServices.JavaScript;
using System.Runtime.Versioning;

[SupportedOSPlatform("browser")]
private static async Task Main(string[] args)
{
    // Import the gondwana-audio JS module before starting Avalonia.
    await JSHost.ImportAsync("gondwana-audio", "./gondwana-audio.js");
    await BuildAvaloniaApp().StartBrowserAppAsync("out");
}

2. Use BrowserAudioManager in your game host

protected override void LoadAssets()
{
    if (OperatingSystem.IsBrowser())
    {
        var audio = Engine.GetBrowserAudioManager();

        _music = audio.Load("music", "assets/theme.mp3", volume: 0.5f, loop: true);
        _sfx   = audio.Load("click", "assets/click.wav");
    }
    else
    {
        // Desktop: use the NAudio-based AudioResourceManager
        _desktopMusic = Engine.Managers.AudioResources.LoadFromFile("music", @"assets\theme.mp3");
        _desktopMusic.IsLooping = true;
    }
}

protected override void OnStartEngine()
{
    if (OperatingSystem.IsBrowser())
        _music?.Play();
    else
        _desktopMusic?.Play();
}

API

BrowserAudioManager

Method Description
Load(key, src, volume, loop) Load a track; returns a BrowserAudioPlayer.
Unload(key) Stop and release a track.
UnloadAll() Stop and release all tracks.
TryGet(key, out player) Try to retrieve a loaded player.
Get(key) Get a player or null.
Contains(key) Check whether a key is loaded.

BrowserAudioPlayer

Member Description
Key The unique track identifier.
Volume Volume in [0.0, 1.0].
IsLooping Whether the track loops.
Play(fromStart) Start or resume playback.
Pause() Pause without resetting.
Stop() Stop and seek to beginning.

Notes

  • Audio autoplay is subject to browser policy: the first Play() call should be triggered by a user gesture.
  • The gondwana-audio.js file must be reachable at ./gondwana-audio.js relative to index.html in the AppBundle.

Documentation

  • Gondwana — Core engine
  • Gondwana.Hosting — Engine bootstrapping and lifecycle
  • Gondwana.Avalonia — Avalonia platform support
  • Gondwana.Avalonia.Hosting — Avalonia hosting

License

MIT

Product Compatible and additional computed target framework versions.
.NET net8.0-browser1.0 is compatible.  net9.0-browser was computed.  net10.0-browser 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

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.2.4 237 5/9/2026
2.2.3 178 5/5/2026