Package com.badlogic.gdx.audio
Interface Sound
- All Superinterfaces:
Disposable
A Sound is a short audio clip that can be played numerous times in parallel. It's completely loaded into memory so only load
small audio files. Call the dispose()
method when you're done using the Sound.
Sound instances are created via a call to Audio.newSound(FileHandle)
.
Calling the play()
or play(float)
method will return a long which is an id to that instance of the sound. You
can use this id to modify the playback of that sound instance.
Note: any values provided will not be clamped, it is the developer's responsibility to do so
-
Method Summary
Modifier and TypeMethodDescriptionvoid
dispose()
Releases all the resources.long
loop()
Plays the sound, looping.long
loop
(float volume) Plays the sound, looping.long
loop
(float volume, float pitch, float pan) Plays the sound, looping.void
pause()
Pauses all instances of this sound.void
pause
(long soundId) Pauses the sound instance with the given id as returned byplay()
orplay(float)
.long
play()
Plays the sound.long
play
(float volume) Plays the sound.long
play
(float volume, float pitch, float pan) Plays the sound.void
resume()
Resumes all paused instances of this sound.void
resume
(long soundId) Resumes the sound instance with the given id as returned byplay()
orplay(float)
.void
setLooping
(long soundId, boolean looping) Sets the sound instance with the given id to be looping.void
setPan
(long soundId, float pan, float volume) Sets the panning and volume of the sound instance with the given id as returned byplay()
orplay(float)
.void
setPitch
(long soundId, float pitch) Changes the pitch multiplier of the sound instance with the given id as returned byplay()
orplay(float)
.void
setVolume
(long soundId, float volume) Changes the volume of the sound instance with the given id as returned byplay()
orplay(float)
.void
stop()
Stops playing all instances of this sound.void
stop
(long soundId) Stops the sound instance with the given id as returned byplay()
orplay(float)
.
-
Method Details
-
play
long play()Plays the sound. If the sound is already playing, it will be played again, concurrently.- Returns:
- the id of the sound instance if successful, or -1 on failure.
-
play
long play(float volume) Plays the sound. If the sound is already playing, it will be played again, concurrently.- Parameters:
volume
- the volume in the range [0,1]- Returns:
- the id of the sound instance if successful, or -1 on failure.
-
play
long play(float volume, float pitch, float pan) Plays the sound. If the sound is already playing, it will be played again, concurrently. Note that (with the exception of the web backend) panning only works for mono sounds, not for stereo sounds!- Parameters:
volume
- the volume in the range [0,1]pitch
- the pitch multiplier, 1 == default, >1 == faster, <1 == slower, the value has to be between 0.5 and 2.0pan
- panning in the range -1 (full left) to 1 (full right). 0 is center position.- Returns:
- the id of the sound instance if successful, or -1 on failure.
-
loop
long loop()Plays the sound, looping. If the sound is already playing, it will be played again, concurrently.- Returns:
- the id of the sound instance if successful, or -1 on failure.
-
loop
long loop(float volume) Plays the sound, looping. If the sound is already playing, it will be played again, concurrently. You need to stop the sound via a call tostop(long)
using the returned id.- Parameters:
volume
- the volume in the range [0, 1]- Returns:
- the id of the sound instance if successful, or -1 on failure.
-
loop
long loop(float volume, float pitch, float pan) Plays the sound, looping. If the sound is already playing, it will be played again, concurrently. You need to stop the sound via a call tostop(long)
using the returned id. Note that (with the exception of the web backend) panning only works for mono sounds, not for stereo sounds!- Parameters:
volume
- the volume in the range [0,1]pitch
- the pitch multiplier, 1 == default, >1 == faster, <1 == slower, the value has to be between 0.5 and 2.0pan
- panning in the range -1 (full left) to 1 (full right). 0 is center position.- Returns:
- the id of the sound instance if successful, or -1 on failure.
-
stop
void stop()Stops playing all instances of this sound. -
pause
void pause()Pauses all instances of this sound. -
resume
void resume()Resumes all paused instances of this sound. -
dispose
void dispose()Releases all the resources.- Specified by:
dispose
in interfaceDisposable
-
stop
void stop(long soundId) Stops the sound instance with the given id as returned byplay()
orplay(float)
. If the sound is no longer playing, this has no effect.- Parameters:
soundId
- the sound id
-
pause
void pause(long soundId) Pauses the sound instance with the given id as returned byplay()
orplay(float)
. If the sound is no longer playing, this has no effect.- Parameters:
soundId
- the sound id
-
resume
void resume(long soundId) Resumes the sound instance with the given id as returned byplay()
orplay(float)
. If the sound is not paused, this has no effect.- Parameters:
soundId
- the sound id
-
setLooping
void setLooping(long soundId, boolean looping) Sets the sound instance with the given id to be looping. If the sound is no longer playing this has no effect.s- Parameters:
soundId
- the sound idlooping
- whether to loop or not.
-
setPitch
void setPitch(long soundId, float pitch) Changes the pitch multiplier of the sound instance with the given id as returned byplay()
orplay(float)
. If the sound is no longer playing, this has no effect.- Parameters:
soundId
- the sound idpitch
- the pitch multiplier, 1 == default, >1 == faster, <1 == slower, the value has to be between 0.5 and 2.0
-
setVolume
void setVolume(long soundId, float volume) Changes the volume of the sound instance with the given id as returned byplay()
orplay(float)
. If the sound is no longer playing, this has no effect.- Parameters:
soundId
- the sound idvolume
- the volume in the range 0 (silent) to 1 (max volume).
-
setPan
void setPan(long soundId, float pan, float volume) Sets the panning and volume of the sound instance with the given id as returned byplay()
orplay(float)
. If the sound is no longer playing, this has no effect. Note that panning only works for mono sounds, not for stereo sounds!- Parameters:
soundId
- the sound idpan
- panning in the range -1 (full left) to 1 (full right). 0 is center position.volume
- the volume in the range [0,1].
-