APIdia Launch Partner
Top Description Methods
com.badlogic.gdx

public Interface Audio

extends Disposable
Imports
com.badlogic.gdx.audio.AudioDevice, .AudioRecorder, .Music, .Sound, com.badlogic.gdx.files.FileHandle, com.badlogic.gdx.utils.Disposable, .GdxRuntimeException, .Null

This interface encapsulates the creation and management of audio resources. It allows you to get direct access to the audio hardware via the AudioDevice and AudioRecorder interfaces, create sound effects via the Sound interface and play music streams via the Music interface.

All resources created via this interface have to be disposed as soon as they are no longer used.

Note that all Music instances will be automatically paused when the ApplicationListener#pause() method is called, and automatically resumed when the ApplicationListener#resume() method is called.

Author
mzechner

Method Summary

Modifier and TypeMethod and Description
public String[]

Returns:

A array of available output devices
getAvailableOutputDevices
()

This function returns a list of fully qualified Output device names.

public AudioDevice

Returns:

the AudioDevice
newAudioDevice
(int
the sampling rate.
samplingRate
,
boolean
whether the AudioDevice should be in mono or stereo mode
isMono
)

Creates a new AudioDevice either in mono or stereo mode.

public AudioRecorder

Returns:

the AudioRecorder
newAudioRecorder
(int
the sampling rate in Hertz
samplingRate
,
boolean
whether the recorder records in mono or stereo
isMono
)

Creates a new AudioRecorder.

public Music

Returns:

the new Music or null if the Music could not be loaded
newMusic
(FileHandle
the FileHandle
file
)

Creates a new Music instance which is used to play back a music stream from a file.

public Sound

Returns:

the new Sound
newSound
(FileHandle fileHandle)

Creates a new Sound which is used to play back audio effects such as gun shots or explosions.

public boolean
switchOutputDevice(String
device identifier to switch to, or null for auto
deviceIdentifier
)

Sets a new OutputDevice.

Inherited from com.badlogic.gdx.utils.Disposable:
dispose

Method Detail

getAvailableOutputDevicesback to summary
public String[] getAvailableOutputDevices()

This function returns a list of fully qualified Output device names. This function is only implemented on desktop and web. Note that on gwt the GwtApplicationConfiguration#fetchAvailableOutputDevices attribute needs to be set to true for asking the user for permission! On all other platforms it will return an empty array. It will also return an empty array on error. The names returned need os dependent preprocessing before exposing to a user.

Returns:String[]

A array of available output devices

newAudioDeviceback to summary
public AudioDevice newAudioDevice(int samplingRate, boolean isMono)

Creates a new AudioDevice either in mono or stereo mode. The AudioDevice has to be disposed via its AudioDevice#dispose() method when it is no longer used.

Parameters
samplingRate:int

the sampling rate.

isMono:boolean

whether the AudioDevice should be in mono or stereo mode

Returns:AudioDevice

the AudioDevice

Exceptions
GdxRuntimeException:
in case the device could not be created
newAudioRecorderback to summary
public AudioRecorder newAudioRecorder(int samplingRate, boolean isMono)

Creates a new AudioRecorder. The AudioRecorder has to be disposed after it is no longer used.

Parameters
samplingRate:int

the sampling rate in Hertz

isMono:boolean

whether the recorder records in mono or stereo

Returns:AudioRecorder

the AudioRecorder

Exceptions
GdxRuntimeException:
in case the recorder could not be created
newMusicback to summary
public Music newMusic(FileHandle file)

Creates a new Music instance which is used to play back a music stream from a file. Currently supported formats are WAV, MP3 and OGG. The Music instance has to be disposed if it is no longer used via the Music#dispose() method. Music instances are automatically paused when ApplicationListener#pause() is called and resumed when ApplicationListener#resume() is called.

Parameters
file:FileHandle

the FileHandle

Returns:Music

the new Music or null if the Music could not be loaded

Exceptions
GdxRuntimeException:
in case the music could not be loaded
newSoundback to summary
public Sound newSound(FileHandle fileHandle)

Creates a new Sound which is used to play back audio effects such as gun shots or explosions. The Sound's audio data is retrieved from the file specified via the FileHandle. Note that the complete audio data is loaded into RAM. You should therefore not load big audio files with this methods. The current upper limit for decoded audio is 1 MB.

Currently supported formats are WAV, MP3 and OGG.

The Sound has to be disposed if it is no longer used via the Sound#dispose() method.

Returns:Sound

the new Sound

Exceptions
GdxRuntimeException:
in case the sound could not be loaded
switchOutputDeviceback to summary
public boolean switchOutputDevice(String deviceIdentifier)

Sets a new OutputDevice. The identifier can be retrieved from Audio#getAvailableOutputDevices(). If null is passed, it will switch to auto.

Parameters
deviceIdentifier:String

device identifier to switch to, or null for auto