Options
All
  • Public
  • Public/Protected
  • All
Menu

Module audio

Index

Variables

defaults: { fadeDuration: number; pauseBetweenTracks: number } = ...

Default values for durations.

Type declaration

  • fadeDuration: number

    The duration of fade in or out, in milliseconds

    default

    1000

  • pauseBetweenTracks: number

    How long to pause between music tracks, in milliseconds

    default

    1000

Functions

  • clearPlaylist(): void
  • Clears the playlist and the music queue. Does not stop music that's currently playing.

    Returns void

  • currentMusicPlaying(): string | null
  • Returns string | null

    Returns the name of the currently playing music file, or null if nothing is playing. If music has been asked to stop, returns the name of the music file that will play next.

  • fadeOut(element: string | PlainObject<any>, duration?: null | number, callback?: ((success: boolean) => void)): boolean
  • Fades out sound.

    Parameters

    • element: string | PlainObject<any>

      The audio element that should fade out

    • duration: null | number = null
    • Optional callback: ((success: boolean) => void)

      Function that is called when the audio has stopped completely with a boolean as the first parameter that matches what this function returned

        • (success: boolean): void
        • Parameters

          • success: boolean

          Returns void

    Returns boolean

    Returns false if the element doesn't exist or is not an audio element, true otherwise.

  • isAudioPlaying(): boolean
  • Checks if any audio is playing. Note that sound that is being loaded or has received a play command but isn't playing for some other reason isn't considered as playing, even though it's about to start.

    Returns boolean

    Returns true if audio is playing, false otherwise.

  • isEffectPlaying(): boolean
  • Checks if any sound effect is playing.

    Returns boolean

    Returns true if a sound effect is playing, false otherwise.

  • isElementPlaying(audioElement: string | PlainObject<any>): boolean
  • Checks if an audio element is playing.

    Parameters

    • audioElement: string | PlainObject<any>

      DOM element, jQuery object or jQuery selector of the audio element

    Returns boolean

    Returns true if audio element exists and is playing, false otherwise.

  • isMusicPlaying(): boolean
  • Checks if music is playing.

    Returns boolean

    Returns true if music is actually playing and it isn't fading out at the moment.

  • Starts playing music. If the same music file is already playing, does nothing except sets the looping property. If another music file is playing, fades out the old one before playing the new one.

    Parameters

    • url: string

      The URL of the audio file

    • options: PlayMusicOptions = {}

      An optional options object

    Returns void

  • Starts playing a sound effect.

    Parameters

    • url: string

      The URL of the audio file

    • options: PlaySoundOptions = {}

      An optional options object

    Returns HTMLAudioElement

    Returns the audio DOM element.

  • Sets a playlist and starts playing it.

    Parameters

    • list: string[]

      An array of music file URLs

    • options: SetPlaylistOptions = {}

      An optional options object

    Returns void

  • stopMusic(fadeoutDuration?: number): void
  • Stops playing music. Clears the music queue and the playlist.

    Parameters

    • fadeoutDuration: number = 1000

      The duration of the fadeout in milliseconds. Set to 0 to stop immediately.

    Returns void

Generated using TypeDoc