Table of Contents

Class SoundPlayer

Namespace
PopcorningGuineaPig.Engine.Services
Assembly
PopcorningGuineaPig.Engine.dll
public class SoundPlayer : ISoundPlayer, IDisposable
Inheritance
SoundPlayer
Implements
Inherited Members

Constructors

SoundPlayer(float)

public SoundPlayer(float volume = 100)

Parameters

volume float

SoundPlayer(string, float)

public SoundPlayer(string playlist, float volume = 100)

Parameters

playlist string
volume float

Fields

currentlyPlayingMusic

protected FileSource? currentlyPlayingMusic

Field Value

FileSource

embeddedResourceAssembly

protected Assembly? embeddedResourceAssembly

Field Value

Assembly

gameMusic

protected List<string> gameMusic

Field Value

List<string>

gameMusicCancellationTokenSource

protected CancellationTokenSource? gameMusicCancellationTokenSource

Field Value

CancellationTokenSource

musicTracks

protected Dictionary<string, FileSource> musicTracks

Field Value

Dictionary<string, FileSource>

playlist

protected string playlist

Field Value

string

sfxGain

protected float sfxGain

Field Value

float

soundEffects

protected Dictionary<string, IAudioSource> soundEffects

Field Value

Dictionary<string, IAudioSource>

volume

protected float volume

Field Value

float

Methods

ApplyMix(float, float, float)

Master × music / master × sfx, each 0..1. Updates the playing music stream immediately. One-shots pick up the sfx gain on the next PlaySound.

public virtual void ApplyMix(float master, float sound, float music)

Parameters

master float
sound float
music float

ClearEmbeddedResourceAssembly()

Clears the embedded resource assembly so audio paths resolve via VFS/file system again.

public void ClearEmbeddedResourceAssembly()

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

GetSoundSource(string)

Gets the source for a loaded sound effect, or null if not loaded. Useful for controlling volume on a playing sound (e.g., fade-out).

public IAudioSource? GetSoundSource(string soundPath)

Parameters

soundPath string

Returns

IAudioSource

LoadMusicIfNeeded(string)

protected void LoadMusicIfNeeded(string musicPath)

Parameters

musicPath string

LoadPlaylists()

protected virtual void LoadPlaylists()

LoadSoundIfNeeded(string)

protected void LoadSoundIfNeeded(string soundPath)

Parameters

soundPath string

PlayGameBackgroundMusic(CancellationToken)

protected Task PlayGameBackgroundMusic(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Returns

Task

PlayMusic(string)

Plays a music track and tracks it as current.

protected void PlayMusic(string musicPath)

Parameters

musicPath string

PlaySound(string, float)

public Task PlaySound(string soundPath, float volume = 1)

Parameters

soundPath string
volume float

Returns

Task

ReleaseSound(string)

Take one sound effect out of the mixer. The decoded clip stays cached, so the next play does not decode it again. Scenes call this when a looping bed ends.

public void ReleaseSound(string soundPath)

Parameters

soundPath string

ResolveAudioPath(string)

Resolves an audio path. If embedded resource assembly is set, extracts the resource to a temp file. Otherwise, returns the path as-is for file-based loading.

protected string ResolveAudioPath(string audioPath)

Parameters

audioPath string

Returns

string

SetEmbeddedResourceAssembly(Assembly)

Sets the assembly to use for loading embedded audio resources. When set, sound/music paths will be treated as embedded resource names and extracted to temp files.

public void SetEmbeddedResourceAssembly(Assembly assembly)

Parameters

assembly Assembly

The assembly containing embedded audio resources

StartGameBackgroundMusic()

public Task StartGameBackgroundMusic()

Returns

Task

StopCurrentMusic()

Stops the currently playing music.

protected void StopCurrentMusic()

StopGameBackgroundMusic()

public Task StopGameBackgroundMusic()

Returns

Task

Update()

OwnAudioSharp manages its own audio thread — no frame-coupled updates needed. Method retained for ISoundPlayer interface compatibility.

public virtual void Update()

UpdateSettings(string, float)

public Task UpdateSettings(string playlist, float volume = 100)

Parameters

playlist string
volume float

Returns

Task