Difference between revisions of "Oolite JavaScript Reference: SoundSource"
(→<code>playSound</code>) |
Eric Walch (talk | contribs) (Added example) |
||
| Line 8: | Line 8: | ||
=== Sound Expressions === | === Sound Expressions === | ||
Several <code>SoundSource</code> properties and methods can take either <code>Sound</code> object, or a string representing a file name or a [[customsounds.plist]] key. | Several <code>SoundSource</code> properties and methods can take either <code>Sound</code> object, or a string representing a file name or a [[customsounds.plist]] key. | ||
| + | |||
| + | == Constructor == | ||
| + | '''new SoundSource''' : SoundSource | ||
| + | Creates a new SoundSource that can be altered. e.g.: | ||
| + | var mySound = new SoundSource; | ||
| + | mySound.sound = "trumblesqueal.ogg"; | ||
| + | mySound.loop = true; | ||
| + | mySound.play(); | ||
| + | |||
== Properties == | == Properties == | ||
Revision as of 13:48, 31 December 2009
Prototype: Object
Subtypes: none
This class was added in Oolite test release 1.71.
A SoundSource is an abstract object that can play a sound. A given SoundSource can only be playing one sound at a particular time.
Contents
Sound Expressions
Several SoundSource properties and methods can take either Sound object, or a string representing a file name or a customsounds.plist key.
Constructor
new SoundSource : SoundSource
Creates a new SoundSource that can be altered. e.g.:
var mySound = new SoundSource; mySound.sound = "trumblesqueal.ogg"; mySound.loop = true; mySound.play();
Properties
isPlaying
isPlaying : Boolean (read-only)
true if the sound is currently playing, false otherwise.
loop
loop : Boolean (read/write)
true if the sound source should loop its sound, false otherwise. Changing this while a sound is playing does not affect the currently-playing sound; it only takes effect when the sound source starts playing.
See Also: repeatCount
repeatCount
repeatCount : Integer (read/write)
The number of times the sound should repeat, if loop is false, ranging from 1 to 100. Unlike loop, this can usefully be changed while the sound is playing, and repeatCount will be decremented each time the sound is repeated.
See Also: loop
sound
sound : soundExpression (read/write)
The sound to be played by this sound source. You can assign either a Oolite JavaScript Reference: Sound or a string to this property, but when you read it it will always be a Oolite JavaScript Reference: Sound object (or null).
Methods
play
play([count : Integer])
Start playing sound. If count is specified, repeatCount is set to count first. If the sound source is currently playing a sound, it is stopped.
See Also: playOrRepeat(), playSound()
playOrRepeat
playOrRepeat()
If a sound is not playing, starts playing. If a sound is playing and is not looping, increases repeatCount by one.
See Also: play()
playSound
play(sound : soundExpression [, count : Integer])
Set sound (and, optionally, repeatCount) and start playing.
See Also: play()
stop
stop()
Stop playing sound.