API Docs for: 1.4.0
Show:

Kiwi.Sound.Audio Class

Defined in: src\sound\Audio.ts:10
Module: Sound
Parent Module: Kiwi

The Audio Object contains the functionality for playing a singular sound in a Kiwi Game. The Audio can contain Audio Sprites which is a nice way to play audio on mobile devices. Audio Objects do not 'die' when game states are switched or changed.

Constructor

Kiwi.Sound.Audio

(
  • game
  • key
  • volume
  • loop
)
Kiwi.Sound.Audio

Parameters:

  • game Kiwi.Game

    The game that this piece of audio belongs to.

  • key String

    The key to which which piece of audio should be loaded from the AudioLibrary.

  • volume Number

    A number between 0 (silence) and 1 (loud).

  • loop Boolean

    If the audio should loop when it is finished or just stop.

Returns:

Kiwi.Sound.Audio:

This object

Methods

_decode

() private

Decodes the audio data to make it playable. By default the audio should already have been decoded when it was loaded.

_setAudio

() private

Retrieves the audio data from the file store.

addMarker

(
  • name
  • start
  • stop
  • [loop=false]
)
public

Adds a new marker to the audio which will then allow for that section of audio to be played.

Parameters:

  • name String

    The name of the marker that you are adding.

  • start Number

    The starting point of the audio. In seconds.

  • stop Number

    The stopping point of the audio. In seconds.

  • [loop=false] Boolean optional

    If the marker's pieve of audio should loop or not.

destroy

() public

This method handles the destruction of all of the properties when this audio is not longer needed. You call this method when you want this method to be removed on the next garbage collection cycle.

objType

() String public

The type of object that this is.

Returns:

String:

"Audio"

pause

() public

Pauses the sound so that you can resume it from at point to paused it at.

play

(
  • [marker]
  • [forceRestart=false]
)
public

Plays the current sound/audio from the start.

Parameters:

  • [marker] String optional

    The marker that is to be played. If no marker is specified then it will play the current marker (which would be the whole audio piece if no marker was ever added).

  • [forceRestart=false] Boolean optional

    Force the audio to stop and start again. Otherwise if the audio was already playing it would ignore the play.

removeMarker

(
  • name
)
public

Removes a currently existing marker from this audio.

Parameters:

  • name String

    name of the audio that you want to remove.

resume

() public

Plays the sound from when you paused the sound.

stop

() public

Stop the sound from playing.

update

() public

The update loop that gets executed every frame.

Properties

_buffer

Any private

Web Audio API ONLY - The audio buffer that is to be used when playing audio segments.

_currentMarker

String private

The current marker that is being used.

Default: 'default'

_currentTime

Number private

When the audio is playing, this is the current time we are at with it playing. In milliseconds

_decoded

Boolean private

Web Audio API ONLY - A boolean to indicate if the audio has been decoded or not yet. If not you will need to run the decode() method.

Default: false

_file

File private

The property containing the file information about the audio.

_game

Kiwi.Game private

The game that this sound belongs to.

_loop

Boolean private

A boolean indicating whether this piece of audio should loop or not.

_markers

Object private

A collection of all of the markers that are on this piece of audio.

_muted

Boolean private

A private indicator of whether this audio is currently muted or not.

Default: false

_muteVolume

Number private

A private property that holds the volume before the sound was muted. Used so that when unmuted the sound will resume at its old spot.

_pending

Boolean private

If the sound needs to be played but we are waiting on particular condition. In the case of CocoonJS, we generally are waiting for the audio 'length' property to have a value.

_playable

Boolean private

A flag that indicates whether the sound is ready to be played or not. If not then this indicates that we are awaiting a user event.

_sound

Any private

This is the piece of audio that either method will use to play audio. E.g. In the case of the Web Audio API this is the sound buffer source, in which the audio plays from. In the case of Audio Tags this is the Audio Tag itself.

_startTime

Number private

When the audio started playing. In milliseconds

_usingAudioTag

Boolean private

A boolean indicating whether or not that audio tags are being used to generate sounds.

_usingWebAudio

Boolean private

A boolean indicating whether or not the webAuduio api is being used.

_volume

Number private

A number between 0 and 1 representing the current volume of this audio piece.

Default: 1

context

Any public

Web Audio API ONLY - A reference to the audio context that the game's audio manager has.

duration

Number public

The current duration of the section of audio that is being played. In milliseconds.

gainNode

Any public

Web Audio API ONLY - This sounds local gainNode that it uses.

id

Number public

A unique ID that this audio gets assigned by the audio manager it belongs to when it is created.

isPlaying

Boolean public

Indicates whether or not the sound is currently playing.

Default: false

key

String public

The key that was used to get the audio from the AudioLibrary.

loop

Boolean public

READ ONLY: Returns a boolean indicating if the current audio marker playing is/will loop.

masterGainNode

Any public

Web Audio API ONLY - A reference to the master gain node on the audio manager.

mute

Boolean public

Mutes the sound and makes it 'silent'. This will not stop the sound from playing, or events from being dispatched due when the sound has finished/is looping.

onComplete

Kiwi.Signal public

A Kiwi Signal that dispatches a event when the audio completes and does not loop.

onLoop

Kiwi.Signal public

A Kiwi Signal that dispatches a event when the audio finishes and starts again, due to it looping.

onMute

Kiwi.Signal public

A Kiwi Signal that dispatches a event when the audio gets muted.

onPause

Kiwi.Signal public

A Kiwi Signal that dispatches a event when the audio gets paused.

onPlay

Kiwi.Signal public

A Kiwi Signal that dispatches a event when the audio starts playing.

onResume

Kiwi.Signal public

A Kiwi Signal that dispatches a event when the audio resumes.

onStop

Kiwi.Signal public

A Kiwi Signal that dispatches a event when the audio stops playing.

paused

Boolean public

A indicator of if the sound is currently paused.

Default: false

playable

Boolean private

Returns whether or not the sound is 'playable' or not. The only time the sound would be not 'playable' is on iOS devices when a mouse/touch event has not fired. Devs should treat this property as READ ONLY.

ready

Boolean public

A boolean that controls/knows if the audio is ready to be played or not. This is just an indicator of if the file has been retrieved successfully from the file store or not.

totalDuration

Number public

The total duration of the audio in seconds.

volume

Number public

Used to control the current volume for this sound. 0 is silent, 1 is full volume.