Construct a Sound by providing the source URL and other options.
The audio source path, either a relative path or a remote URL
Optional options: { Additional options which configure the Sound
A non-default audio context within which the sound should play
Force use of an AudioBufferSourceNode even if the audio duration is long
A unique integer identifier for this sound.
The audio source path. Either a relative path served by the running Foundry VTT game server or a remote URL.
The GainNode used to control volume for this sound.
An AudioBuffer instance, if this Sound uses an AudioBufferSourceNode for playback.
An HTMLAudioElement, if this Sound uses a MediaElementAudioSourceNode for playback.
The AudioNode destination which is the output target for the Sound.
A pipeline of AudioNode instances to be applied to Sound playback.
The time in seconds at which playback was started.
The time in seconds at which playback was paused.
Internal _managerAn internal reference to some object which is managing this Sound instance.
Protected _stateThe life-cycle state of the sound.
Private #bufferWhen this Sound uses an AudioBuffer, this is an AudioBufferSourceNode.
Private #mediaWhen this Sound uses an HTML Audio stream, this is a MediaElementAudioSourceNode.
Private #playbackPlayback configuration options specified at the time that Sound#play is called.
Private #forceForce usage of an AudioBufferSourceNode regardless of audio duration?
Private #pipelineRecord the pipeline of nodes currently used by this Sound.
Private #scheduledA set of scheduled events orchestrated using the Sound#schedule function.
Private #operationAn operation in progress on the sound which must be queued.
Private #delayA delay timeout before the sound starts or stops.
Private #eventsA mapping of registered events.
Static STATESThe sequence of container loading states.
Static MAX_The maximum duration, in seconds, for which an AudioBufferSourceNode will be used. Otherwise, a MediaElementAudioSourceNode will be used.
Static emittedStatic Private #nodeAn incrementing counter used to assign each Sound a unique id.
The audio context within which this Sound is played.
The AudioSourceNode used to control sound playback.
Has the audio file been loaded either fully or for streaming.
Did the audio file fail to load.
Is this sound currently playing?
Does this Sound use an AudioBufferSourceNode? Otherwise, the Sound uses a streamed MediaElementAudioSourceNode.
A convenience reference to the GainNode gain audio parameter.
The currently playing volume of the sound. Undefined until playback has started for the first time.
The total duration of the audio source in seconds.
The current playback time of the sound.
Is the sound looping?
Load the audio source and prepare it for playback, either using an AudioBuffer or a streamed HTMLAudioElement.
Optional options: { Additional options which affect resource loading
Automatically begin playback of the sound once loaded
Playback options passed to Sound#play, if autoplay
A Promise which resolves to the Sound once it is loaded
Begin playback for the Sound. This method is asynchronous because playback may not start until after an initially provided delay. The Promise resolves before the fade-in of any configured volume transition.
Optional options: SoundPlaybackOptions = {}Options which configure the beginning of sound playback
Rest ...args: anyA Promise which resolves once playback has started (excluding fade)
Pause playback of the Sound. For AudioBufferSourceNode this stops playback after recording the current time. Calling Sound#play will resume playback from the pausedTime unless some other offset is passed. For a MediaElementAudioSourceNode this simply calls the HTMLAudioElement#pause method directly.
Stop playback for the Sound. This method is asynchronous because playback may not stop until after an initially provided delay. The Promise resolves after the fade-out of any configured volume transition.
Optional options: SoundPlaybackOptions = {}Options which configure the stopping of sound playback
A Promise which resolves once playback is fully stopped (including fade)
Fade the volume for this sound between its current level and a desired target volume.
The desired target volume level between 0 and 1
Optional options: { Additional options that configure the fade operation
The duration of the fade effect in milliseconds
A volume level to start from, the current volume by default
The type of fade easing, "linear" or "exponential"
A Promise that resolves after the requested fade duration
Schedule a function to occur at the next occurrence of a specific playbackTime for this Sound.
A function that will be called with this Sound as its single argument
The desired playback time at which the function should be called
A Promise which resolves to the returned value of the provided function once it has been evaluated.
sound.schedule(() => console.log("Do something exactly 30 seconds into the track"), 30);
sound.schedule(() => console.log("Do something next time the track loops back to the beginning"), 0);
sound.schedule(() => console.log("Do something 5 seconds before the end of the track"), sound.duration - 5);
Add a new event listener for a certain type of event.
The type of event being registered for
The listener function called when the event occurs
Optional options: { Options which configure the event listener
Should the event only be responded to once and then removed
Remove an event listener for a certain type of event.
The type of event being removed
The listener function being removed
Protected _loadProtected An inner method which handles loading so that it can be de-duplicated under a single shared Promise resolution. This method is factored out to allow for subclasses to override loading behavior.
A Promise which resolves once the sound is loaded
An error if loading failed for any reason
Protected _playProtected _pauseProtected _stopProtected _createProtected _connectProtected _disconnectPrivate #queueAn inner method that is wrapped in an enqueued promise. See Sound#play.
Private #queueAn inner method that is wrapped in an enqueued promise. See Sound#stop.
Private #onPrivate #onPrivate #onPrivate #onPrivate #createPrivate #createPrivate #configureConfigure playback parameters for the Sound.
playback options
Private #cancelStatic Private #unload
A container around an AudioNode which manages sound playback in Foundry Virtual Tabletop. Each Sound is either an AudioBufferSourceNode (for short sources) or a MediaElementAudioSourceNode (for long ones). This class provides an interface around both types which allows standardized control over playback.
Alias
foundry.audio.Sound
See