A pc.SoundInstance plays a pc.Sound
|currentTime||Gets or sets the current time of the sound that is playing.|
|duration||The duration of the sound that the instance will play starting from startTime.|
|isPaused||Returns true if the instance is currently paused.|
|isPlaying||Returns true if the instance is currently playing.|
|isStopped||Returns true if the instance is currently stopped.|
|isSuspended||Returns true if the instance is currently suspended because the window is not focused.|
|loop||If true the instance will restart when it finishes playing|
|pitch||The pitch modifier to play the sound with.|
|sound||The sound resource that the instance will play.|
|source||Gets the source that plays the sound resource.|
|startTime||The start time from which the sound will start playing.|
|volume||The volume modifier to play the sound with.|
|clearExternalNodes||Clears any external nodes set by pc.SoundInstance#setExternalNodes.|
|getExternalNodes||Gets any external nodes set by pc.SoundInstance#setExternalNodes.|
|pause||Pauses playback of sound.|
|play||Begins playback of sound.|
|resume||Resumes playback of the sound.|
|setExternalNodes||Connects external Web Audio API nodes.|
|stop||Stops playback of sound.|
|end||Fired when the sound currently played by the instance ends.|
|pause||Fired when the instance is paused.|
|play||Fired when the instance starts playing its source|
|resume||Fired when the instance is resumed.|
|stop||Fired when the instance is stopped.|
SoundInstance(manager, sound, options)
|manager||pc.SoundManager||The sound manager|
|sound||pc.Sound||The sound to play|
|options||Object||Options for the instance|
|options.volume||Number||The playback volume, between 0 and 1.|
|options.pitch||Number||The relative pitch, default of 1, plays at normal pitch.|
|options.loop||Boolean||Whether the sound should loop when it reaches the end or not.|
|options.startTime||Number||The time from which the playback will start. Default is 0 to start at the beginning.|
|options.duration||Number||The total time after the startTime when playback will stop or restart if loop is true.|
|options.onPlay||function||Function called when the instance starts playing.|
|options.onPause||function||Function called when the instance is paused.|
|options.onResume||function||Function called when the instance is resumed.|
|options.onStop||function||Function called when the instance is stopped.|
|options.onEnd||function||Function called when the instance ends.|
Gets or sets the current time of the sound that is playing. If the value provided is bigger than the duration of the instance it will wrap from the beginning.
Returns true if the instance is currently suspended because the window is not focused.
Gets the source that plays the sound resource. If the Web Audio API is not supported the type of source is Audio. Source is only available after calling play.
Gets any external nodes set by pc.SoundInstance#setExternalNodes.
ReturnsAudioNode Returns an array that contains the two nodes set by pc.SoundInstance#setExternalNodes.
Pauses playback of sound. Call resume() to resume playback from the same position.
ReturnsBoolean Returns true if the sound was paused
Begins playback of sound. If the sound is not loaded this will return false. If the sound is already playing this will restart the sound.
ReturnsBoolean True if the sound was started.
Resumes playback of the sound. Playback resumes at the point that the audio was paused
ReturnsBoolean Returns true if the sound was resumed.
Connects external Web Audio API nodes. You need to pass the first node of the node graph that you created externally and the last node of that graph. The first node will be connected to the audio source and the last node will be connected to the destination of the AudioContext (e.g speakers). Requires Web Audio API support.
var context = app.systems.sound.context; var analyzer = context.createAnalyzer(); var distortion = context.createWaveShaper(); var filter = context.createBiquadFilter(); analyzer.connect(distortion); distortion.connect(filter); instance.setExternalNodes(analyzer, filter);
|firstNode||AudioNode||The first node that will be connected to the audio source of sound instances.|
|lastNode||AudioNode||The last node that will be connected to the destination of the AudioContext. If unspecified then the firstNode will be connected to the destination instead.|
Stops playback of sound. Calling play() again will restart playback from the beginning of the sound.
Fired when the sound currently played by the instance ends.
Fired when the instance is paused.
Fired when the instance starts playing its source
Fired when the instance is resumed.
Fired when the instance is stopped.