API Documentation for: 1.0.6
Show:

SwishSprite Class

Extends EventDispatcher
Defined in: SwishSprite:13
Namespace: cloudkid

This class is responsible for playback of an audiosprite file (multiple sounds in a single timeline) using HTML5 audio

Constructor

SwishSprite

(
  • data
)

Defined in SwishSprite:13

Parameters:

  • data

    The name of the audio file to load, array of resources, or a spritemap

Methods

_callbackIndex

(
  • name
  • callback
)
Int private

Returns callback array index.

Parameters:

Returns:

Int:

Callback array index, or -1 if isn't registered.

checkUpdate

()

Defined in checkUpdate:955

1 second update to check what the status of the scrubber is

clear

() SwishSprite

Defined in clear:571

Clear all of the current sounds

Returns:

SwishSprite:

Return this SwishSprite

destroy

()

Defined in destroy:837

Destroy the audiosprite, don't use after this must recreate the SwishSprite

getAudioElement

() DOMElement

Defined in getAudioElement:370

Get the audio element

Returns:

DOMElement:

The audio element

getLength

(
  • alias
)
Int

Defined in getLength:480

Get the length of a sprite

Parameters:

  • alias String

    The optional alias, or get the current

Returns:

Int:

The duration in seconds

getPosition

() Int

Defined in getPosition:500

Get the current position in seconds of the audio

Returns:

Int:

The duration in seconds

getSound

(
  • alias
)
DOMElement

Defined in getSound:515

Get a sound by name

Parameters:

  • alias String

    The sound name, optional, if no sound name returns the current

Returns:

DOMElement:

The sound

initialize

(
  • data
)

Defined in initialize:313

Create the audio sprite

Parameters:

  • data

    The name of the audio file to load, array of resources, or a spritemap

isLoaded

() Bool

Defined in isLoaded:889

Get whether the audio has been loaded yet

Returns:

Bool:

If loaded

load

() SwishSprite

Defined in load:583

For iOS, start loading the audio via user click

Returns:

SwishSprite:

Return this SwishSprite

mute

() SwishSprite

Defined in mute:381

Mute the audio, not available on all devices

Returns:

SwishSprite:

Return this SwishSprite

off

(
  • name
  • callback
)

Inherited from EventDispatcher: off:94

Remove the event listener

Parameters:

  • name String*

    The type of event string separated by spaces, if no name is specifed remove all listeners.

  • callback Function | Array*

    The listener function or collection of callback functions

on

(
  • name
  • callback
)
EventDispatcher

Inherited from EventDispatcher: on:46

Add an event listener

Parameters:

  • name String | Object

    The type of event (can be multiple events separated by spaces), or a map of events to handlers

  • callback Function | Array*

    The callback function when event is fired or an array of callbacks.

Returns:

EventDispatcher:

Return this EventDispatcher

onBlur

()

Defined in onBlur:920

Callback when page visibility has gone to hidden

onCanPlayThrough

()

Callback on canplaythrough event

onFocus

()

Defined in onFocus:937

Callback when page visibility has gone to show

onLoadChange

()

Defined in onLoadChange:1019

Function call when load state has changed

onLoadStarted

()

Defined in onLoadStarted:899

Function call when load has started

onPlayTimeout

()

Defined in onPlayTimeout:1076

Callback on playback timeout

onStalled

()

Defined in onStalled:1102

Callback when audio has stalled

pause

() SwishSprite

Defined in pause:405

Pause the sound playback

Returns:

SwishSprite:

Return this SwishSprite

play

(
  • alias
  • playStartTime
)
Bool

Defined in play:646

Play a sound sprite

Parameters:

  • alias String

    The sprite name

  • playStartTime Int

    The play start time

Returns:

Bool:

If playback succeeded

playUpdate

()

Defined in playUpdate:761

The play updating function

prepare

(
  • alias
)

Defined in prepare:559

Set the current time to the start alias

Parameters:

  • alias String

    The name of the sound alias

resume

() SwishSprite

Defined in resume:439

Unpause the audio playback

Returns:

SwishSprite:

Return this SwishSprite

setSound

(
  • alias
  • startTime
  • duration
  • isLoop
)
SwishSprite

Defined in setSound:534

Add a sound to the list of playable sounds

Parameters:

  • alias String

    The name of the audio

  • startTime Int

    Sound's start time

  • duration Int

    Length of the sound

  • isLoop Bool

    Whether the sound should loop

Returns:

SwishSprite:

Return this SwishSprite

soundPlayComplete

()

When sound has completed callback

stop

() SwishSprite

Defined in stop:459

Stop the sound playback clear the current sound playing

Returns:

SwishSprite:

Return this SwishSprite

trigger

(
  • type
  • params
)

Inherited from EventDispatcher: trigger:27

Dispatch an event

Parameters:

  • type String

    The event string name,

  • params

    Additional parameters

type

(
  • value
)
String private

Inherited from EventDispatcher: type:142

Return type of the value.

Parameters:

  • value

Returns:

String:

The type

unmute

() SwishSprite

Defined in unmute:393

Unmute the audio, not available on all devices

Returns:

SwishSprite:

Return this SwishSprite

update

()

Defined in update:630

The update function, call this manually if manualUpdate is set to true

Properties

_audio

DOMElement private

Defined in _audio:30

The audio element

_autoPaused

Int private

Defined in _autoPaused:205

Keep track of the paused state when the page blur/focuses a value of -1 means the page isn't hidden, 0 means the playing before blur, and 1 means paused before blur

_checkInterval

String private

Defined in _checkInterval:173

The interval ID for checking audio

_formatPadding

Int private

Defined in _formatPadding:118

Some formats require a little padding to the end of a sprite

_instance

SwishSprite private

Defined in _instance:189

The singleton instance of the audiosprite

_lastCurrentTime

Int private

The last current time played

_lastScrubberPos

Int private

The position of the last scrubber

_listeners

Array private

Inherited from EventDispatcher: _listeners:20

The collection of listeners

_loadAmount

Int private

Defined in _loadAmount:102

The previous interval loaded percentage

_loaded

Bool private

Defined in _loaded:46

If the current audio has been loaded

_loadInterval

String private

Defined in _loadInterval:86

The interval ID for loading

_loadStarted

Bool private

Defined in _loadStarted:70

If the load has started

_outOfRangeCount

Int private

If we're out of round

_pageVisibility

PageVisibility private

Defined in _pageVisibility:197

Instance of page visibility for pause/resuming on page blur/focus

_paused

Bool private

Defined in _paused:38

If we're paused

_playingAlias

String private

Defined in _playingAlias:126

The sound name of the current sprite we're playing

_playInterval

String private

Defined in _playInterval:78

The interval ID for playback

_playTimeout

String private

Defined in _playTimeout:94

The playback timeout ID

_scrubberMoved

Bool private

Defined in _scrubberMoved:134

If the scrubber playhead has moved

_scrubberNotMovingCount

Int private

The num of times the scrubber has not moved

_scrubberStartTime

Int private

The start time for the scrubber

_sounds

Array private

Defined in _sounds:110

The collection of sounds

_successfullyPlayedSound

Bool private

If the sound successfully played

_updatingLoad

Bool private

Defined in _updatingLoad:54

If the loading update should run

_updatingPlay

Bool private

Defined in _updatingPlay:62

If the playing update should run

M4A_PADDING

Float final static

Defined in M4A_PADDING:286

A little padding for the m4a audio format will help add extra time for the Kindle Fire who likes to end the sound too early

manualUpdate

Bool

Defined in manualUpdate:305

If using external update call, you can use this to save performance if you're already running a frame update call (such as request animation frame)

VERSION

String final static

Defined in VERSION:296

The version of this library

Events

complete

Defined in complete:244

Event dispatched when sound play completed

loaded

Defined in loaded:230

Event dispatched with audio loaded

loadProgress

Defined in loadProgress:237

Event dispatched when percentage of load changed

loadStarted

Defined in loadStarted:223

Event dispatched when load has started

paused

Defined in paused:258

The playback has been paused

progress

Defined in progress:251

The progress event

resumed

Defined in resumed:265

The sound has been unpaused

started

Defined in started:279

The sound has begun playing

stopped

Defined in stopped:272

The sound has been stopped or canceled