Shaku

Shaku JS

Back To Table of Content

Sound Instance

SoundInstance

A sound effect instance you can play and stop.

Kind: global class

new SoundInstance(sfxManager, url)

Create a sound instance.

Param Type Description
sfxManager Sfx Sfx manager instance.
url String Sound URL or source.

soundInstance.playbackRate ⇒ Number

Get sound effect playback rate.

Kind: instance property of SoundInstance
Returns: Number - Playback rate.

soundInstance.playbackRate

Set playback rate.

Kind: instance property of SoundInstance

Param Type Description
val Number Playback value to set.

soundInstance.preservesPitch ⇒ Boolean

Get if to preserve pitch while changing playback rate.

Kind: instance property of SoundInstance
Returns: Boolean - Preserve pitch state of the sound instance.

soundInstance.preservesPitch

Set if to preserve pitch while changing playback rate.

Kind: instance property of SoundInstance

Param Type Description
val Boolean New preserve pitch value to set.

soundInstance.loop ⇒ Boolean

Get if playing in loop.

Kind: instance property of SoundInstance
Returns: Boolean - If this sound should play in loop.

soundInstance.loop

Set if playing in loop.

Kind: instance property of SoundInstance

Param Type Description
value Boolean If this sound should play in loop.

soundInstance.volume ⇒ Number

Get volume.

Kind: instance property of SoundInstance
Returns: Number - Sound effect volume.

soundInstance.volume

Set volume.

Kind: instance property of SoundInstance

Param Type Description
value Number Sound effect volume to set.

soundInstance.currentTime ⇒ Number

Get current time in track.

Kind: instance property of SoundInstance
Returns: Number - Current time in playing sound.

soundInstance.currentTime

Set current time in track.

Kind: instance property of SoundInstance

Param Type Description
value Number Set current playing time in sound track.

soundInstance.duration ⇒ Number

Get track duration.

Kind: instance property of SoundInstance
Returns: Number - Sound duration in seconds.

soundInstance.paused ⇒ Boolean

Get if sound is currently paused.

Kind: instance property of SoundInstance
Returns: Boolean - True if sound is currently paused.

soundInstance.playing ⇒ Boolean

Get if sound is currently playing.

Kind: instance property of SoundInstance
Returns: Boolean - True if sound is currently playing.

soundInstance.finished ⇒ Boolean

Get if finished playing.

Kind: instance property of SoundInstance
Returns: Boolean - True if sound reached the end and didn’t loop.

soundInstance.disposeWhenDone()

Dispose the audio object when done playing the sound. This will call dispose() automatically when audio ends.

Kind: instance method of SoundInstance

soundInstance.dispose()

Dispose the audio object and clear its resources. When playing lots of sounds its important to call dispose on sounds you no longer use, to avoid getting hit by “Blocked attempt to create a WebMediaPlayer” exception.

Kind: instance method of SoundInstance

soundInstance.play() ⇒ Promise

Play sound.

Kind: instance method of SoundInstance
Returns: Promise - Promise to return when sound start playing.

soundInstance.pause()

Pause the sound.

Kind: instance method of SoundInstance

soundInstance.replay() ⇒ Promise

Replay sound from start.

Kind: instance method of SoundInstance
Returns: Promise - Promise to return when sound start playing.

soundInstance.stop() ⇒ Boolean

Stop the sound and go back to start.

Kind: instance method of SoundInstance
Returns: Boolean - True if successfully stopped sound, false otherwise.