Class: AudioPlayer

AudioPlayer

Class representing an audio player with playback control capabilities. Supports playing, pausing, resuming, and stopping audio files with volume control and playback speed adjustment.


new AudioPlayer()

Creates an instance of AudioPlayer. Initializes the player with default settings and sets up signal handling for events.

Source:

Methods


<async> continue()

Resumes playback of a paused audio file.

Source:
Returns:

Resolves when the resumed audio playback completes.

Type
Promise.<void>

emit(type)

Emits an event of the specified type

Parameters:
Name Type Description
type string

The event type to emit

Source:

getPlayDuration()

Returns the total play duration in milliseconds.

Source:
Returns:

Total play duration in milliseconds.

Type
number

pause()

Pauses the currently playing audio. Updates play duration when pausing.

Source:

<async> play(audioFile [, speed])

Plays an audio file with optional playback speed adjustment. If audio is paused, it will resume playback instead of starting a new file.

Parameters:
Name Type Argument Default Description
audioFile string

The path or URL to the audio file.

speed number <optional>
1.0

Playback speed multiplier (1.0 is normal speed).

Source:
Returns:

Resolves when the audio playback completes.

Type
Promise.<void>

setMute(b)

Set the mute state of the audio player. Stores the previous volume level when muting and restores it when unmuting.

Parameters:
Name Type Description
b boolean

Whether to mute the audio playback

Source:

setVolume(volume)

Sets the audio volume level.

Parameters:
Name Type Description
volume number

Volume level between 0.0 and 1.0.

Source:

<async> silence(ms)

Creates a delay in the execution flow.

Parameters:
Name Type Description
ms number

Number of milliseconds to wait.

Source:
Returns:

Resolves after the specified delay.

Type
Promise.<void>

stop()

Stops the current audio playback and resets all player states. Removes event listeners and updates final play duration.

Source: