public class Sound
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
Sound.Error
Represents a sound that failed to load.
|
Modifier and Type | Field and Description |
---|---|
RFuture<Sound> |
state
Reports the asynchronous loading of this sound.
|
Constructor and Description |
---|
Sound()
Creates the sound of silence.
|
Modifier and Type | Method and Description |
---|---|
boolean |
isLoaded()
Returns whether this sound is fully loaded.
|
boolean |
isPlaying()
Determine whether this audio stream is currently playing.
|
boolean |
play()
If possible, begin playback of this audio stream.
|
boolean |
prepare()
Prepares this sound to be played by preloading it into audio buffers.
|
void |
release()
Releases resources used by this sound.
|
void |
setLooping(boolean looping)
Set whether audio stream playback should be looped indefinitely or not.
|
void |
setVolume(float volume) |
void |
stop()
Stop playback of the current audio stream as soon as possible, and reset the sound position to
its starting position, such that a subsequent call to
play() will cause the audio file
to being playback from the beginning of the audio stream. |
float |
volume() |
public boolean isLoaded()
state
to do things only after a sound is loaded, but this method is useful if you want to just skip
playing a sound that's not fully loaded (because playing a sound that's not loaded will defer
the play request until it has loaded, which may result in mismatched audio and visuals).
Note: this is different from prepare()
. This has to do with loading the sound bytes
from storage (or over the network in the case of the HTML backend). prepare()
attempts
to ensure that the sound bytes are then transferred from CPU memory into the appropriate audio
buffers so that they can be played with the lowest possible latency.
public boolean prepare()
play()
start emitting sound with the lowest possible
latency.public boolean play()
public void stop()
play()
will cause the audio file
to being playback from the beginning of the audio stream.public void setLooping(boolean looping)
looping
- true if the audio stream should be looped indefinitelypublic float volume()
public void setVolume(float volume)
volume
- new volume between 0.0 and 1.0public boolean isPlaying()
public void release()
Copyright © 2019. All Rights Reserved.