logoBMates

AudioPlayer

AudioPlayer is a class that manages audio playback and editing functionalities. It handles loading audio tracks, controlling playback, and managing audio effects.

Properties

name: string

The name of the audio player. The default value is 'AudioPlayer'.

tracks: Map<string, Map<string, Audio>>

A map that stores audio tracks, organized by track IDs and audio IDs.

_duration: number

The total duration of all loaded tracks.

audioContext: AudioContext | null

The audio context used for audio processing.

Constructor

constructor();

Initializes a new instance of the AudioPlayer.

Methods

createContext ()

Creates and initializes the audio context.

  • Return: AudioContext

loadAudioBuffer (src)

Loads an audio buffer from the specified source URL.

NameTypeDescription
srcstringThe URL of the audio source.
  • Return: Promise<AudioBuffer>

prepareTrackAll (waves)

Prepare an audio source from multiple wave objects.

NameTypeDescription
wavesWave[]Wave components.

prepareWave (waves)

Prepare an audio source from a wave object.

NameTypeDescription
wavesWaveWave components.

play (startTime)

Starts playback of the audio tracks.

NameTypeDescription
startTimenumberThe time to start playback.
Default value is 0.

pause ()

Pauses the currently playing tracks.

stop ()

Stops all currently playing tracks.

mute (trackId, isMuted)

Mutes or unmutes the specified track.

NameTypeDescription
trackIdstringThe ID of the track to mute.
isMutedboolean
undefined
The mute state to set.

isMuted (trackId)

Checks if the specified track is muted.

NameTypeDescription
trackIdstringThe ID of the track to check.
  • Return: boolean

getAudioBuffer (trackId)

Retrieves the audio buffer for the specified track.

NameTypeDescription
trackIdstringThe ID of the track.
  • Return: AudioBuffer | undefined

getDuration ()

Returns the total duration of all loaded tracks.

  • Return: number

async toBlob ()

Converts the currently loaded audio tracks into a single Blob. This function merges the audio buffers of all tracks and transforms the merged audio buffer into a Blob.

  • Return: Promise<Blob>

async downloadBlob (filename)

Downloads the Blob with the specified filename. This function calls the toBlob function to create the Blob and then uses the generated Blob to perform the file download.

NameTypeDescription
filenamestringThe name of the file to download.

setTrackGroup(trackgroup)

Specifies the trackgroup the AudioPlayer will track.

Manages audio based on specified track groups.

Usage Example

const audioPlayer = new AudioPlayer();
const songData: SongDataType = {};
await Promise.all([audioPlayer.prepareTrack(songData, 'track1')]);
audioPlayer.play();
PREVEventNEXTWorkground
logoBMates