APIdia Launch Partner
Top Description Methods
com.badlogic.gdx.audio

public Interface Sound

extends Disposable
Imports
com.badlogic.gdx.Audio, com.badlogic.gdx.files.FileHandle, com.badlogic.gdx.utils.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

Author
[email protected]

Method Summary

Modifier and TypeMethod and Description
public void
dispose()

Redeclares com.badlogic.gdx.utils.Disposable.dispose.

Releases all the resources.

public long

Returns:

the id of the sound instance if successful, or -1 on failure.
loop
()

Plays the sound, looping.

public long

Returns:

the id of the sound instance if successful, or -1 on failure.
loop
(float
the volume in the range [0, 1]
volume
)

Plays the sound, looping.

public long

Returns:

the id of the sound instance if successful, or -1 on failure.
loop
(float
the volume in the range [0,1]
volume
,
float
the pitch multiplier, 1 == default, >1 == faster, <1 == slower, the value has to be between 0.5 and 2.0
pitch
,
float
panning in the range -1 (full left) to 1 (full right). 0 is center position.
pan
)

Plays the sound, looping.

public void
pause()

Pauses all instances of this sound.

public void
pause(long
the sound id
soundId
)

Pauses the sound instance with the given id as returned by play() or play(float).

public long

Returns:

the id of the sound instance if successful, or -1 on failure.
play
()

Plays the sound.

public long

Returns:

the id of the sound instance if successful, or -1 on failure.
play
(float
the volume in the range [0,1]
volume
)

Plays the sound.

public long

Returns:

the id of the sound instance if successful, or -1 on failure.
play
(float
the volume in the range [0,1]
volume
,
float
the pitch multiplier, 1 == default, >1 == faster, <1 == slower, the value has to be between 0.5 and 2.0
pitch
,
float
panning in the range -1 (full left) to 1 (full right). 0 is center position.
pan
)

Plays the sound.

public void
resume()

Resumes all paused instances of this sound.

public void
resume(long
the sound id
soundId
)

Resumes the sound instance with the given id as returned by play() or play(float).

public void
setLooping(long
the sound id
soundId
,
boolean
whether to loop or not.
looping
)

Sets the sound instance with the given id to be looping.

public void
setPan(long
the sound id
soundId
,
float
panning in the range -1 (full left) to 1 (full right). 0 is center position.
pan
,
float
the volume in the range [0,1].
volume
)

Sets the panning and volume of the sound instance with the given id as returned by play() or play(float).

public void
setPitch(long
the sound id
soundId
,
float
the pitch multiplier, 1 == default, >1 == faster, <1 == slower, the value has to be between 0.5 and 2.0
pitch
)

Changes the pitch multiplier of the sound instance with the given id as returned by play() or play(float).

public void
setVolume(long
the sound id
soundId
,
float
the volume in the range 0 (silent) to 1 (max volume).
volume
)

Changes the volume of the sound instance with the given id as returned by play() or play(float).

public void
stop()

Stops playing all instances of this sound.

public void
stop(long
the sound id
soundId
)

Stops the sound instance with the given id as returned by play() or play(float).

Method Detail

disposeback to summary
public void dispose()

Redeclares com.badlogic.gdx.utils.Disposable.dispose.

Releases all the resources.

loopback to summary
public long loop()

Plays the sound, looping. If the sound is already playing, it will be played again, concurrently.

Returns:long

the id of the sound instance if successful, or -1 on failure.

loopback to summary
public 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 to stop(long) using the returned id.

Parameters
volume:float

the volume in the range [0, 1]

Returns:long

the id of the sound instance if successful, or -1 on failure.

loopback to summary
public 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 to stop(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:float

the volume in the range [0,1]

pitch:float

the pitch multiplier, 1 == default, >1 == faster, <1 == slower, the value has to be between 0.5 and 2.0

pan:float

panning in the range -1 (full left) to 1 (full right). 0 is center position.

Returns:long

the id of the sound instance if successful, or -1 on failure.

pauseback to summary
public void pause()

Pauses all instances of this sound.

pauseback to summary
public void pause(long soundId)

Pauses the sound instance with the given id as returned by play() or play(float). If the sound is no longer playing, this has no effect.

Parameters
soundId:long

the sound id

playback to summary
public long play()

Plays the sound. If the sound is already playing, it will be played again, concurrently.

Returns:long

the id of the sound instance if successful, or -1 on failure.

playback to summary
public long play(float volume)

Plays the sound. If the sound is already playing, it will be played again, concurrently.

Parameters
volume:float

the volume in the range [0,1]

Returns:long

the id of the sound instance if successful, or -1 on failure.

playback to summary
public 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:float

the volume in the range [0,1]

pitch:float

the pitch multiplier, 1 == default, >1 == faster, <1 == slower, the value has to be between 0.5 and 2.0

pan:float

panning in the range -1 (full left) to 1 (full right). 0 is center position.

Returns:long

the id of the sound instance if successful, or -1 on failure.

resumeback to summary
public void resume()

Resumes all paused instances of this sound.

resumeback to summary
public void resume(long soundId)

Resumes the sound instance with the given id as returned by play() or play(float). If the sound is not paused, this has no effect.

Parameters
soundId:long

the sound id

setLoopingback to summary
public 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:long

the sound id

looping:boolean

whether to loop or not.

setPanback to summary
public void setPan(long soundId, float pan, float volume)

Sets the panning and volume of the sound instance with the given id as returned by play() or play(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:long

the sound id

pan:float

panning in the range -1 (full left) to 1 (full right). 0 is center position.

volume:float

the volume in the range [0,1].

setPitchback to summary
public void setPitch(long soundId, float pitch)

Changes the pitch multiplier of the sound instance with the given id as returned by play() or play(float). If the sound is no longer playing, this has no effect.

Parameters
soundId:long

the sound id

pitch:float

the pitch multiplier, 1 == default, >1 == faster, <1 == slower, the value has to be between 0.5 and 2.0

setVolumeback to summary
public void setVolume(long soundId, float volume)

Changes the volume of the sound instance with the given id as returned by play() or play(float). If the sound is no longer playing, this has no effect.

Parameters
soundId:long

the sound id

volume:float

the volume in the range 0 (silent) to 1 (max volume).

stopback to summary
public void stop()

Stops playing all instances of this sound.

stopback to summary
public void stop(long soundId)

Stops the sound instance with the given id as returned by play() or play(float). If the sound is no longer playing, this has no effect.

Parameters
soundId:long

the sound id