Gondwana Game Engine Development (master) - 2.6.1
Gondwana is a cross-platform 2.5D game and rendering engine written in C#/.NET 8. It provides fine-grained control over rendering, timing, and scene composition, with built-in support for parallax, z-ordering, pixel overhang, collision detection, and particle effects. Gondwana targets desktop and web platforms using SkiaSharp for graphics and pluggable audio backends for desktop and browser targets.
Loading...
Searching...
No Matches
BrowserAudioBackend.cs
1using System.Runtime.Versioning;
2
4
6[SupportedOSPlatform("browser")]
7public sealed class BrowserAudioBackend : IAudioBackend
8{
9 private BrowserAudioBackend() { }
10
14 public static BrowserAudioBackend Instance { get; } = new();
15
17 public string Name => "Browser Audio";
18
21 string key,
22 byte[] data,
23 string fileNameOrExtension,
24 float volume,
25 float pan,
26 float playbackSpeed)
27 {
28 ArgumentNullException.ThrowIfNull(data);
29
30 return new BrowserAudioPlaybackHandle(
31 key,
32 data,
33 ResolveMimeType(fileNameOrExtension),
34 volume,
35 pan,
36 playbackSpeed);
37 }
38
41 string key,
42 string uri,
43 float volume,
44 float pan,
45 float playbackSpeed)
46 => new BrowserAudioPlaybackHandle(key, uri, volume, pan, playbackSpeed);
47
48 private static string ResolveMimeType(string fileNameOrExtension)
49 {
50 var extension = Path.GetExtension(fileNameOrExtension);
51 if (string.IsNullOrWhiteSpace(extension) && fileNameOrExtension.StartsWith('.'))
52 extension = fileNameOrExtension;
53
54 return extension.ToLowerInvariant() switch
55 {
56 ".aac" => "audio/aac",
57 ".flac" => "audio/flac",
58 ".m4a" => "audio/mp4",
59 ".mp3" => "audio/mpeg",
60 ".ogg" => "audio/ogg",
61 ".opus" => "audio/ogg",
62 ".wav" => "audio/wav",
63 ".webm" => "audio/webm",
64 _ => "application/octet-stream"
65 };
66 }
67}
static BrowserAudioBackend Instance
Gets the shared instance.
string Name
Gets the human-readable name of the backend implementation.
IAudioPlaybackHandle CreateFromUri(string key, string uri, float volume, float pan, float playbackSpeed)
Creates a playback handle that plays audio from the specified URI. This is intended for backends that...
IAudioPlaybackHandle CreateFromBytes(string key, byte[] data, string fileNameOrExtension, float volume, float pan, float playbackSpeed)
Creates a playback handle from raw audio bytes. The implementation is responsible for interpreting th...
Creates backend-specific playback handles for the engine's common audio API.
Backend-provided playback handle used by AudioResource. Implements IDisposable to allow releasing any...