SwishSprite Class
This class is responsible for playback of an audiosprite file (multiple sounds in a single timeline) using HTML5 audio
Constructor
SwishSprite
-
data
Parameters:
-
data
The name of the audio file to load, array of resources, or a spritemap
Item Index
Methods
- _callbackIndex
- checkUpdate
- clear
- destroy
- getAudioElement
- getLength
- getPosition
- getSound
- initialize
- isLoaded
- load
- mute
- off
- on
- onBlur
- onCanPlayThrough
- onFocus
- onLoadChange
- onLoadStarted
- onPlayTimeout
- onStalled
- pause
- play
- playUpdate
- prepare
- resume
- setSound
- soundPlayComplete
- stop
- trigger
- type
- unmute
- update
Properties
- _audio
- _autoPaused
- _checkInterval
- _formatPadding
- _instance
- _lastCurrentTime
- _lastScrubberPos
- _listeners
- _loadAmount
- _loaded
- _loadInterval
- _loadStarted
- _outOfRangeCount
- _pageVisibility
- _paused
- _playingAlias
- _playInterval
- _playTimeout
- _scrubberMoved
- _scrubberNotMovingCount
- _scrubberStartTime
- _sounds
- _successfullyPlayedSound
- _updatingLoad
- _updatingPlay
- M4A_PADDING static
- manualUpdate
- VERSION static
Methods
_callbackIndex
-
name
-
callback
Returns callback array index.
Returns:
Callback array index, or -1 if isn't registered.
checkUpdate
()
1 second update to check what the status of the scrubber is
destroy
()
Destroy the audiosprite, don't use after this must recreate the SwishSprite
getAudioElement
()
DOMElement
Get the audio element
Returns:
The audio element
getLength
-
alias
Get the length of a sprite
Parameters:
-
alias
StringThe optional alias, or get the current
Returns:
The duration in seconds
getPosition
()
Int
Get the current position in seconds of the audio
Returns:
The duration in seconds
getSound
-
alias
Get a sound by name
Parameters:
-
alias
StringThe sound name, optional, if no sound name returns the current
Returns:
The sound
initialize
-
data
Create the audio sprite
Parameters:
-
data
The name of the audio file to load, array of resources, or a spritemap
isLoaded
()
Bool
Get whether the audio has been loaded yet
Returns:
If loaded
load
()
SwishSprite
For iOS, start loading the audio via user click
Returns:
Return this SwishSprite
mute
()
SwishSprite
Mute the audio, not available on all devices
Returns:
Return this SwishSprite
off
-
name
-
callback
Remove the event listener
on
-
name
-
callback
Add an event listener
Parameters:
Returns:
Return this EventDispatcher
onBlur
()
Callback when page visibility has gone to hidden
onCanPlayThrough
()
Callback on canplaythrough event
onFocus
()
Callback when page visibility has gone to show
onLoadChange
()
Function call when load state has changed
onLoadStarted
()
Function call when load has started
onPlayTimeout
()
Callback on playback timeout
onStalled
()
Callback when audio has stalled
play
-
alias
-
playStartTime
Play a sound sprite
Parameters:
-
alias
StringThe sprite name
-
playStartTime
IntThe play start time
Returns:
If playback succeeded
playUpdate
()
The play updating function
prepare
-
alias
Set the current time to the start alias
Parameters:
-
alias
StringThe name of the sound alias
setSound
-
alias
-
startTime
-
duration
-
isLoop
Add a sound to the list of playable sounds
Parameters:
-
alias
StringThe name of the audio
-
startTime
IntSound's start time
-
duration
IntLength of the sound
-
isLoop
BoolWhether the sound should loop
Returns:
Return this SwishSprite
soundPlayComplete
()
When sound has completed callback
stop
()
SwishSprite
Stop the sound playback clear the current sound playing
Returns:
Return this SwishSprite
trigger
-
type
-
params
Dispatch an event
Parameters:
-
type
StringThe event string name,
-
params
Additional parameters
unmute
()
SwishSprite
Unmute the audio, not available on all devices
Returns:
Return this SwishSprite
update
()
The update function, call this manually if manualUpdate is set to true
Properties
_audio
DOMElement
private
The audio element
_autoPaused
Int
private
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
_formatPadding
Int
private
Some formats require a little padding to the end of a sprite
_lastCurrentTime
Int
private
The last current time played
_lastScrubberPos
Int
private
The position of the last scrubber
_loadAmount
Int
private
The previous interval loaded percentage
_loaded
Bool
private
If the current audio has been loaded
_loadStarted
Bool
private
If the load has started
_outOfRangeCount
Int
private
If we're out of round
_pageVisibility
PageVisibility
private
Instance of page visibility for pause/resuming on page blur/focus
_paused
Bool
private
If we're paused
_scrubberMoved
Bool
private
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
_successfullyPlayedSound
Bool
private
If the sound successfully played
_updatingLoad
Bool
private
If the loading update should run
_updatingPlay
Bool
private
If the playing update should run
M4A_PADDING
Float
final
static
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
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)
Events
complete
Event dispatched when sound play completed
loaded
Event dispatched with audio loaded
loadProgress
Event dispatched when percentage of load changed
loadStarted
Event dispatched when load has started
paused
The playback has been paused
progress
The progress event
resumed
The sound has been unpaused
started
The sound has begun playing
stopped
The sound has been stopped or canceled