public class Sound
extends java.lang.Object
A Sound is a sound effect. Like Sprites, SpriteSheets, and Music tracks, Sounds can be manually loaded and unloaded into and out of memory. Loading may take a moment, but while a Sound is not loaded, it cannot play.
Constructor and Description |
---|
Sound(java.lang.String path,
boolean load)
Creates a new Sound from an audio file.
|
Modifier and Type | Method and Description |
---|---|
boolean |
isLoaded()
Returns whether this Sound is loaded.
|
boolean |
isPlaying()
Returns whether this Sound is currently playing.
|
boolean |
load()
Loads this Sound if it is not already loaded.
|
void |
play()
Plays this Sound once.
|
void |
play(boolean loop)
Plays this Sound.
|
void |
play(double speed,
double volume)
Plays this Sound once at the specified speed and volume.
|
void |
play(double speed,
double volume,
boolean loop)
Plays this Sound at the specified speed and volume.
|
void |
stop()
Stops this Sound.
|
boolean |
unload()
Unloads this Sound if it is currently loaded.
|
public Sound(java.lang.String path, boolean load)
path
- The relative path to the audio fileload
- Whether this Sound should load upon creationpublic final boolean isLoaded()
public final boolean load()
public final boolean unload()
public final boolean isPlaying()
public final void play(boolean loop)
loop
- If true, this Sound will loop indefinitely until stopped;
otherwise, it will play oncepublic final void play(double speed, double volume, boolean loop)
speed
- The speed at which to play this Sound, with 1 representing
no speed changevolume
- The volume at which to play this Sound, with 1 representing
no volume changeloop
- If true, this Sound will loop indefinitely until stopped;
otherwise, it will play oncepublic final void play()
public final void play(double speed, double volume)
speed
- The speed at which to play this Sound, with 1 representing
no speed changevolume
- The volume at which to play this Sound, with 1 representing
no volume changepublic final void stop()