public class Sound extends java.lang.Object implements Loadable
A Sound is a sound effect. Like other Loadables, 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.
Sounds can be played at different speeds from 0 up, with a speed of 0 making the Sound inaudible and a speed of 1 causing no speed change. They can also be played at different volumes between 0 and 1, with a volume of 0 making the Sound inaudible and a volume of 1 causing no volume change. Finally, the Sound class has a global volume between 0 and 1, by which the effective volumes of all newly played Sounds are scaled. The global volume is 1 by default.
Constructor and Description |
---|
Sound(java.lang.String path,
boolean load)
Constructs a Sound from an audio file.
|
Modifier and Type | Method and Description |
---|---|
static double |
getGlobalVolume()
Returns the global sound volume.
|
boolean |
isLoaded()
Returns whether this Loadable is loaded.
|
boolean |
isPlaying()
Returns whether this Sound is currently playing.
|
boolean |
load()
Loads this Loadable 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.
|
static void |
setGlobalVolume(double volume)
Sets the global sound volume to the specified value.
|
void |
stop()
Stops this Sound.
|
boolean |
unload()
Unloads this Loadable 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 static double getGlobalVolume()
public static void setGlobalVolume(double volume)
volume
- The new global sound volumepublic final boolean isLoaded()
Loadable
public final boolean load()
Loadable
public final boolean unload()
Loadable
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 Soundvolume
- The volume at which to play this Soundloop
- 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 Soundvolume
- The volume at which to play this Soundpublic final void stop()