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

public Interface Music

extends Disposable
Imports
com.badlogic.gdx.Application, .ApplicationListener, .Audio, com.badlogic.gdx.files.FileHandle, com.badlogic.gdx.utils.Disposable

A Music instance represents a streamed audio file. The interface supports pausing, resuming and so on. When you are done with using the Music instance you have to dispose it via the dispose() method.

Music instances are created via Audio#newMusic(FileHandle).

Music instances are automatically paused and resumed when an Application is paused or resumed. See ApplicationListener.

Note

any values provided will not be clamped, it is the developer's responsibility to do so

Author
mzechner

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
Music.OnCompletionListener

Interface definition for a callback to be invoked when playback of a music stream has completed.

Method Summary

Modifier and TypeMethod and Description
public void
dispose()

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

Needs to be called when the Music is no longer needed.

public float
getPosition()

Returns the playback position in seconds.

public float
getVolume()

Returns: the volume of this music stream.

public boolean
isLooping()

Returns: whether the music stream is playing.

public boolean
isPlaying()

Returns: whether this music stream is playing

public void
pause()

Pauses the play back.

public void
play()

Starts the play back of the music stream.

public void
setLooping(boolean
whether to loop the stream
isLooping
)

Sets whether the music stream is looping.

public void
setOnCompletionListener(Music.OnCompletionListener
the callback that will be run.
listener
)

Register a callback to be invoked when the end of a music stream has been reached during playback.

public void
setPan(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 this music stream.

public void
setPosition(float position)

Set the playback position in seconds.

public void
setVolume(float volume)

Sets the volume of this music stream.

public void
stop()

Stops a playing or paused Music instance.

Method Detail

disposeback to summary
public void dispose()

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

Needs to be called when the Music is no longer needed.

getPositionback to summary
public float getPosition()

Returns the playback position in seconds.

getVolumeback to summary
public float getVolume()
Returns:float

the volume of this music stream.

isLoopingback to summary
public boolean isLooping()
Returns:boolean

whether the music stream is playing.

isPlayingback to summary
public boolean isPlaying()
Returns:boolean

whether this music stream is playing

pauseback to summary
public void pause()

Pauses the play back. If the music stream has not been started yet or has finished playing a call to this method will be ignored.

playback to summary
public void play()

Starts the play back of the music stream. In case the stream was paused this will resume the play back. In case the music stream is finished playing this will restart the play back.

setLoopingback to summary
public void setLooping(boolean isLooping)

Sets whether the music stream is looping. This can be called at any time, whether the stream is playing.

Parameters
isLooping:boolean

whether to loop the stream

setOnCompletionListenerback to summary
public void setOnCompletionListener(Music.OnCompletionListener listener)

Register a callback to be invoked when the end of a music stream has been reached during playback.

Parameters
listener:Music.OnCompletionListener

the callback that will be run.

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

Sets the panning and volume of this music stream.

Parameters
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].

setPositionback to summary
public void setPosition(float position)

Set the playback position in seconds.

setVolumeback to summary
public void setVolume(float volume)

Sets the volume of this music stream. The volume must be given in the range [0,1] with 0 being silent and 1 being the maximum volume.

stopback to summary
public void stop()

Stops a playing or paused Music instance. Next time play() is invoked the Music will start from the beginning.

com.badlogic.gdx.audio back to summary

public Interface Music.OnCompletionListener


Interface definition for a callback to be invoked when playback of a music stream has completed.

Method Summary

Modifier and TypeMethod and Description
public void
onCompletion(Music
the Music that reached the end of the file
music
)

Called when the end of a media source is reached during playback.

Method Detail

onCompletionback to summary
public void onCompletion(Music music)

Called when the end of a media source is reached during playback.

Parameters
music:Music

the Music that reached the end of the file