Class: PlayAudio

PlayAudio(audioSrc, shouldLoopopt, volumeopt, backroundSoundopt)

Represents a wrapper around the HTML Audio element, providing methods to play, pause, stop, and mute sounds or background music. It also stores and retrieves mute state from localStorage.

Constructor

new PlayAudio(audioSrc, shouldLoopopt, volumeopt, backroundSoundopt)

Constructs a new PlayAudio instance, creates an HTMLAudioElement from the given source, configures its looping and volume, and checks for stored mute state.
Parameters:
Name Type Attributes Default Description
audioSrc string The path or URL of the audio file.
shouldLoop boolean <optional>
false Determines if the audio should loop.
volume number <optional>
1 The initial volume of the audio.
backroundSound boolean <optional>
false Indicates whether this audio is background music.
Source:

Members

muted :boolean

Indicates whether the audio is currently muted.
Type:
  • boolean
Source:

Methods

mutedSound()

Checks stored mute state in localStorage and applies it to the audio, depending on whether this instance is for background music or sound effects.
Source:

pause()

Pauses the audio without resetting its playback position.
Source:

play(newVolumeopt)

Plays the audio if it is not muted. Can optionally set a new volume before playing.
Parameters:
Name Type Attributes Description
newVolume number <optional>
The new volume level to set before playing, if provided.
Source:

setMute(isMuted)

Sets the mute state of this audio instance, updates the HTMLAudioElement's muted property, and stores the mute preference in localStorage.
Parameters:
Name Type Description
isMuted boolean Whether the audio should be muted.
Source:

stop()

Stops the audio by pausing it and resetting its playback position to the beginning.
Source: