Gleam - v1.0.2
    Preparing search index...

    Class Music

    Background music with eased cross-fades. Tracks auto-cycle: when the current track ends, the next one fades in. Inherits registration, enable/disable, and volume from AudioBase.

    Random track picking excludes the previous two songs to avoid back-to-back repeats. If only one track is registered, it's looped instead of faded.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    Accessors

    Methods

    Constructors

    Properties

    songs: Map<string, HTMLAudioElement> = ...

    Registered audio elements keyed by name. Subclasses read this; mutate via register.

    Accessors

    • get enabled(): boolean

      Whether music playback is permitted (inherited from AudioBase).

      Returns boolean

    • set enabled(value: boolean): void

      Flipping from false to true while no music is playing auto-starts a fade-in to a random track.

      Parameters

      • value: boolean

      Returns void

    • get isPlaying(): boolean

      true while a fade is in progress OR the current track is actively playing.

      Returns boolean

    Methods

    • Cross-fade to name (or a random unplayed track when null) over fadeTime ms. easing.cur controls the outgoing track's volume curve, easing.next the incoming one. Cancels any in-progress fade. No-op when disabled. Throws on fadeTime <= 0, an empty registry, or an unknown name. When the new track ends, the next fade fires automatically — call stop to break the cycle.

      Parameters

      • name: string | null = null
      • fadeTime: number = 1000
      • easing: { cur: EasingName; next: EasingName } = ...

      Returns void

    • Load and register one or more audio files. Each entry may be a bare URL string (the file's basename becomes the name) or a RegisterData object. Per-song volume falls back to defaultVolume. Call once per instance — throws on a second invocation, on non-finite volume, or on volume outside [0, 1]. Load failures are logged to console.error but don't throw.

      Parameters

      • defaultVolume: number = 1
      • ...songs: (string | RegisterData)[]

      Returns void

    • Stop everything immediately: cancels any in-flight fade, halts current and next tracks, and breaks the auto-cycle chain. Restart via fade or by flipping enabled.

      Returns void