libgdx API

com.badlogic.gdx.audio
Interface Sound

All Superinterfaces:
Disposable

public interface Sound
extends 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.

Author:
badlogicgames@gmail.com

Method Summary
 void dispose()
          Releases all the resources.
 long loop()
          Plays the sound, looping.
 long loop(float volume)
          Plays the sound, looping.
 long play()
          Plays the sound.
 long play(float volume)
          Plays the sound.
 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 by play() or play(float).
 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).
 void setVolume(long soundId, float volume)
          Changes the volume of the sound instance with the given id as returned by play() or play(float).
 void stop()
          Stops playing all instances of this sound.
 void stop(long soundId)
          Stops the sound instance with the given id as returned by play() or play(float).
 

Method Detail

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.

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

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

loop

long loop(float volume)
Plays the sound, looping. 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

stop

void stop()
Stops playing all instances of this sound.


dispose

void dispose()
Releases all the resources.

Specified by:
dispose in interface Disposable

stop

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 - 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 id
looping - 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 by play() or play(float). If the sound is no longer playing, this has no effect.

Parameters:
soundId - the sound id
pitch - the pitch multiplier, 1 == default, >1 == faster, <1 == slower

setVolume

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 - the sound id
volume - 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 by play() or play(float). If the sound is no longer playing, this has no effect.

Parameters:
soundId - the sound id
pan - panning in the range -1 (full right) to 1 (full left). 0 is center position.
volume - the volume in the range [0,1].

libgdx API

Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)