API Docs for: v0.1.0
Show:

AudioManager Class

Extends Object

Grapefruit Audio API, provides an easy interface to use WebAudoiAPI with a fallback to HTML5 Audio The GF Audio API was originally based on Howler.js Generally you will use this via the game.audio or state.audio properties.

Constructor

AudioManager

(
  • game
  • parent
)

Parameters:

  • game Game

    The game instance this manager belongs to

  • parent AudioManager

    The parent audio manager this manager belongs to. This is used to create a web audio API node heirarchy.

Methods

add

(
  • key
  • [settings]
)
AudioPlayer

Creates a new audio player for a peice of audio

Parameters:

  • key String

    The unique cache key for the preloaded audio

  • [settings] Object optional

    All the settings for the audio player

    • [volume] Number optional

      The volume of this audio clip

    • [autoplay] Boolean optional

      Automatically start playing after loaded

    • [loop] Boolean optional

      Replay the audio when it finishes

    • [sprite] Object optional

      A map of string names -> [start, duration] arrays. You can use it to put multiple sounds in one file

    • [pos3d] Array optional

      3D coords of where the audio should sound as if it came from (only works with WebAudio)

    • [buffer] Boolean optional

      WebAudio will load the entire file before playing, making this true forces HTML5Audio which will buffer and play

    • [format] String optional

      Force an extension override

Returns:

AudioPlayer:

Will return the new audio player, or false if we couldn't determine a compatible url

attach

(
  • sound
)
AudioPlayer

Attaches an AudioPlayer to this manager, if using webAudio this means that the sound will connect to this masterGain node and inherit anything that happens to it (such as muting).

Parameters:

  • sound AudioPlayer

    The player to attach to this manager

Returns:

AudioPlayer:

The newly attached audio player

detach

(
  • sound
)
AudioPlayer

Detaches an AudioPlayer from this manager, if using webAudio this means that the sound will disconnect from this masterGain node and stop inheriting anything that happens to it (such as muting).

Parameters:

  • sound AudioPlayer

    The player to detach from this manager

Returns:

AudioPlayer:

The detached audio player

getVolume

()

Returns the current master volume

mute

() AudioManager chainable

Mutes all playing audio

Returns:

AudioManager:

Returns itself.

remove

(
  • key
)
AudioPlayer

Removes an audio player from the manager

Parameters:

  • key String

    The unique cache key for the preloaded audio

Returns:

AudioPlayer:

Will return the audio player removed, or false if none was removed

setMuted

() AudioManager chainable

Sets whether or not this manager is muted

Returns:

AudioManager:

Returns itself.

setParent

(
  • parent
)
AudioManager chainable

Sets the parent of this audio manager, if using webAudio this means that we connect to the parent masterGain node and inherit anything that happens to it (such as muting).

Parameters:

  • parent AudioManager

    The parent to connect to, or null to connect to the global context

Returns:

AudioManager:

Returns itself.

setVolume

(
  • value
)

Sets the current master volume

Parameters:

  • value Number

unmute

() AudioManager chainable

Unmutes all playing audio

Returns:

AudioManager:

Returns itself.

Properties

_volume

Number private

The master volume of the player

Default: 1

canPlay

Boolean

If we have some way of playing audio

ctx

AudioContext

The Web Audio API context if we are using it

game

Game

The game instance this manager belongs to

muted

Boolean private

Whether the player is muted or not

Default: false

parent

AudioManager

The parent for this audio manager

volume

Number

The master volume of all the audio playing

Default: 1