logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Class ThemeAudioPlayer

    Single guarded entry point for theme UI-sound playback and clip-map construction.
    A null play use case, an unset/empty service id, or a null/missing clip results in a silent no-op instead of a crash, so themes with empty, partial, or duplicated sound slots never throw.

    Inheritance
    object
    ThemeAudioPlayer
    Inherited Members
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    Namespace: Serenity.AudioPlayer.Application.UseCases
    Assembly: Serenity.AudioPlayer.Application.dll
    Syntax
    public static class ThemeAudioPlayer

    Methods

    BuildClipMap(params AudioPlayerClip[])

    Builds a clip map keyed by GetId().
    Uses indexer assignment, so a clip reused across several theme slots collapses to a single entry instead of throwing ArgumentException the way Dictionary.Add would. null clips and clips with an empty id are skipped.

    Declaration
    public static Dictionary<string, AudioPlayerClip> BuildClipMap(params AudioPlayerClip[] clips)
    Parameters
    Type Name Description
    AudioPlayerClip[] clips

    The clips to index. A null array yields an empty map.

    Returns
    Type Description
    Dictionary<string, AudioPlayerClip>

    A dedup-safe map from clip id to clip.

    TryPlay(AudioPlayerPlayClip, string, AudioPlayerClip)

    Plays a clip if, and only if, every requirement is met; otherwise does nothing.

    Declaration
    public static bool TryPlay(AudioPlayerPlayClip play, string audioServiceId, AudioPlayerClip clip)
    Parameters
    Type Name Description
    AudioPlayerPlayClip play

    The play use case. A null value is a no-op.

    string audioServiceId

    Audio service id. A null or empty value is a no-op.

    AudioPlayerClip clip

    The clip to play. A null value is a no-op.

    Returns
    Type Description
    bool

    true if the clip was played; false if any guard short-circuited playback.

    TryPlay(AudioPlayerPlayClip, string, IReadOnlyDictionary<string, AudioPlayerClip>, string)

    Plays the clip stored under sfxKey in clips, if present.
    A missing key means that theme sound slot was left empty (all slots are optional): it is a no-op, never a KeyNotFoundException.

    Declaration
    public static bool TryPlay(AudioPlayerPlayClip play, string audioServiceId, IReadOnlyDictionary<string, AudioPlayerClip> clips, string sfxKey)
    Parameters
    Type Name Description
    AudioPlayerPlayClip play

    The play use case. A null value is a no-op.

    string audioServiceId

    Audio service id. A null or empty value is a no-op.

    IReadOnlyDictionary<string, AudioPlayerClip> clips

    The clip map. A null map is a no-op.

    string sfxKey

    Key of the clip to play. A null, empty, or absent key is a no-op.

    Returns
    Type Description
    bool

    true if the clip was played; false if any guard short-circuited playback.

    In this article
    © 2026 Serenity. All Rights Reserved