@game-vir/audio - v15.1.1
    Preparing search index...

    Class AudioFile

    An individual audio file.

    Hierarchy

    Index

    Constructors

    Properties

    audioCache: AudioFileCache

    Cache of all loaded audio files. When an AudioFile instance is part of an AudioPlayer, this cache will be provided by the parent AudioPlayer and shared between all AudioFile instances.

    audioContext: BaseAudioContext

    AudioContext for creating and playing audio nodes. This is automatically provided by a parent AudioPlayer.

    fetch: (url: string) => Promise<Pick<Response, "arrayBuffer">>

    Internal fetch implementation to use. This can be overridden with AudioFileParams.fetch.

    globalThis.fetch
    
    gainNode: GainNode
    isAudioAllowed: boolean = ...

    If true, indicates that this AudioFile instance (or another instance within the same AudioPlayer) has detected that the current browser session is allowing audio playback. Most browsers these days block audio on initial page load until the user has interacted with the page.

    isDestroyed: boolean = ...

    Indicates if the AudioFile has been destroyed. If it has, this file should not be interacted with anymore. This is set by running AudioFile.destroy.

    loadPromise: undefined | Promise<AudioBuffer>
    • undefined indicates that loading has not yet started (or has been unloaded).
    • Promise means that loading has begun (and might be finished).
    outputNode: AudioNode

    The AudioNode that all playback should route to. If effects are provided, this will be the first effect (because it'll sequentially route through all of the following effects, eventually into the final volume GainNode). If no effects are provided, this will simply be the internal volume GainNode.

    urlOrBase64: string

    The url or base64 string chosen from the originally provided list of sources that is most compatible with the current browser. This is what will be played.

    Methods

    • Destroys this audio file entirely; it cannot be used anymore.

      Returns Promise<void>

    • Load the audio file so it's ready to play. This will automatically be called on the first AudioFile.play call, but doing so will introduce latency to the first play.

      Returns Promise<AudioBuffer>

    • Load the audio file's AudioBuffer through one of the following:

      • Retrieving it from the cache (if it exists) using AudioFile.urlOrBase64
      • Parsing the base64 encoded source string (if the source string is encoded base64)
      • Fetching the file URL from the internet

      If a cache entry for this file does not already exist, this will create one.

      Returns Promise<AudioBuffer>

    • Play the audio file. If the audio file has not been loaded yet, it will be loaded before playing. If audio playing is disabled (which these days is often the case until the user interacts with the page), the file will not play. This resolves when the audio file has finished playing.

      Returns Promise<boolean>

      Whether or not the audio file was actually played. The audio file will not be played if audio is currently disabled.