Class SoundPlayer
public class SoundPlayer : ISoundPlayer, IDisposable
- Inheritance
-
SoundPlayer
- Implements
- Inherited Members
Constructors
SoundPlayer(float)
public SoundPlayer(float volume = 100)
Parameters
volumefloat
SoundPlayer(string, float)
public SoundPlayer(string playlist, float volume = 100)
Parameters
Fields
currentlyPlayingMusic
protected FileSource? currentlyPlayingMusic
Field Value
- FileSource
embeddedResourceAssembly
protected Assembly? embeddedResourceAssembly
Field Value
gameMusic
protected List<string> gameMusic
Field Value
gameMusicCancellationTokenSource
protected CancellationTokenSource? gameMusicCancellationTokenSource
Field Value
musicTracks
protected Dictionary<string, FileSource> musicTracks
Field Value
- Dictionary<string, FileSource>
playlist
protected string playlist
Field Value
sfxGain
protected float sfxGain
Field Value
soundEffects
protected Dictionary<string, IAudioSource> soundEffects
Field Value
- Dictionary<string, IAudioSource>
volume
protected float volume
Field Value
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
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
soundPathstring
Returns
- IAudioSource
LoadMusicIfNeeded(string)
protected void LoadMusicIfNeeded(string musicPath)
Parameters
musicPathstring
LoadPlaylists()
protected virtual void LoadPlaylists()
LoadSoundIfNeeded(string)
protected void LoadSoundIfNeeded(string soundPath)
Parameters
soundPathstring
PlayGameBackgroundMusic(CancellationToken)
protected Task PlayGameBackgroundMusic(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationToken
Returns
PlayMusic(string)
Plays a music track and tracks it as current.
protected void PlayMusic(string musicPath)
Parameters
musicPathstring
PlaySound(string, float)
public Task PlaySound(string soundPath, float volume = 1)
Parameters
Returns
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
soundPathstring
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
audioPathstring
Returns
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
assemblyAssemblyThe assembly containing embedded audio resources
StartGameBackgroundMusic()
public Task StartGameBackgroundMusic()
Returns
StopCurrentMusic()
Stops the currently playing music.
protected void StopCurrentMusic()
StopGameBackgroundMusic()
public Task StopGameBackgroundMusic()
Returns
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)