public class Music
extends java.lang.Object
A Music track is a piece of music that can be played in the background of a CellGame. All playing and stopping of Music tracks is controlled by methods of a CellGame so that the CellGame can keep track of them in its music stack.
Like Sprites, SpriteSheets, and Sounds, Music tracks can be manually loaded and unloaded into and out of memory. Loading may take a moment, but while a Music track is not loaded, it cannot play.
Modifier and Type | Field and Description |
---|---|
static Music |
BLANK
A blank Music track that produces no sound and plays indefinitely.
|
Constructor and Description |
---|
Music(java.lang.String path,
boolean load)
Creates a new Music track from an audio file.
|
Music(java.lang.String path,
double loopStart,
double loopEnd,
boolean load)
Creates a new Music track from an audio file.
|
Modifier and Type | Method and Description |
---|---|
void |
fadeOut(double duration)
Instructs the music player to gradually fade this Music track's volume to
0 over the specified duration, stopping this Music track once it is
silent, if it is currently playing.
|
void |
fadeSpeed(double speed,
double duration)
Instructs the music player to gradually fade this Music track's speed to
the specified speed over the specified duration, if this Music track is
currently playing.
|
void |
fadeVolume(double volume,
double duration)
Instructs the music player to gradually fade this Music track's volume to
the specified volume over the specified duration, if this Music track is
currently playing.
|
double |
getPosition()
Returns the music player's position in seconds in this Music track, or 0
if it is not currently playing.
|
double |
getSpeed()
Returns the speed at which this Music track is playing, with 1
representing no speed change, or 0 if it is not currently playing.
|
double |
getVolume()
Returns the volume at which this Music track is playing, with 1
representing no volume change, or 0 if it is not currently playing.
|
boolean |
isLoaded()
Returns whether this Music track is loaded.
|
boolean |
isLooping()
Returns whether this Music track is currently looping indefinitely.
|
boolean |
isPaused()
Returns whether this Music track is currently paused.
|
boolean |
isPlaying()
Returns whether this Music track is currently playing.
|
boolean |
load()
Loads this Music track if it is not already loaded.
|
void |
pause()
Pauses this Music track if it is currently playing.
|
void |
resume()
Resumes playing this Music track if it currently paused.
|
void |
setLooping(boolean loop)
Sets whether this Music track is looping indefinitely, if it is currently
playing.
|
void |
setPosition(double position)
Sets the music player's position in seconds in this Music track, if it is
currently playing.
|
void |
setSpeed(double speed)
Sets the speed at which this Music track is playing, with 1 representing
no speed change, if it is currently playing.
|
void |
setVolume(double volume)
Sets the volume at which this Music track is playing, with 1 representing
no volume change, if it is currently playing.
|
boolean |
unload()
Unloads this Music track if it is currently loaded.
|
public static final Music BLANK
public Music(java.lang.String path, boolean load)
path
- The relative path to the audio fileload
- Whether this Music track should load upon creationpublic Music(java.lang.String path, double loopStart, double loopEnd, boolean load)
path
- The relative path to the audio fileloopStart
- The position in seconds in this Music track to which it
should return at the start of a looploopEnd
- The position in seconds in this Music track that, when
reached, causes it to start a new loop if it is looping. If this is
negative, this Music track will start a new loop when it reaches the end
of the track.load
- Whether this Music track should load upon creationpublic final boolean isLoaded()
public final boolean load()
public final boolean unload()
public final boolean isPlaying()
public final boolean isPaused()
public final void pause()
public final void resume()
public final double getPosition()
public final void setPosition(double position)
position
- The music player's new position in seconds in this Music
trackpublic final double getSpeed()
public final void setSpeed(double speed)
speed
- The speed at which this Music track should playpublic final void fadeSpeed(double speed, double duration)
speed
- This Music track's eventual speedduration
- The fade's duration in secondspublic final double getVolume()
public final void setVolume(double volume)
volume
- The volume at which this Music track should playpublic final void fadeVolume(double volume, double duration)
volume
- This Music track's eventual volumeduration
- The fade's duration in secondspublic final void fadeOut(double duration)
duration
- The duration in seconds of the fade-outpublic final boolean isLooping()
public final void setLooping(boolean loop)
loop
- Whether this Music track should loop indefinitely