Interface Audio
-
public interface AudioThis interface encapsulates the creation and management of audio resources. It allows you to get direct access to the audio hardware via theAudioDeviceandAudioRecorderinterfaces, create sound effects via theSoundinterface and play music streams via theMusicinterface.All resources created via this interface have to be disposed as soon as they are no longer used.
Note that all
Musicinstances will be automatically paused when theApplicationListener.pause()method is called, and automatically resumed when theApplicationListener.resume()method is called.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.String[]getAvailableOutputDevices()This function returns a list of fully qualified Output device names.AudioDevicenewAudioDevice(int samplingRate, boolean isMono)Creates a newAudioDeviceeither in mono or stereo mode.AudioRecordernewAudioRecorder(int samplingRate, boolean isMono)Creates a newAudioRecorder.MusicnewMusic(FileHandle file)Creates a newMusicinstance which is used to play back a music stream from a file.SoundnewSound(FileHandle fileHandle)Creates a newSoundwhich is used to play back audio effects such as gun shots or explosions.booleanswitchOutputDevice(java.lang.String deviceIdentifier)Sets a new OutputDevice.
-
-
-
Method Detail
-
newAudioDevice
AudioDevice newAudioDevice(int samplingRate, boolean isMono)
Creates a newAudioDeviceeither in mono or stereo mode. The AudioDevice has to be disposed via itsAudioDevice.dispose()method when it is no longer used.- Parameters:
samplingRate- the sampling rate.isMono- whether the AudioDevice should be in mono or stereo mode- Returns:
- the AudioDevice
- Throws:
GdxRuntimeException- in case the device could not be created
-
newAudioRecorder
AudioRecorder newAudioRecorder(int samplingRate, boolean isMono)
Creates a newAudioRecorder. The AudioRecorder has to be disposed after it is no longer used.- Parameters:
samplingRate- the sampling rate in HertzisMono- whether the recorder records in mono or stereo- Returns:
- the AudioRecorder
- Throws:
GdxRuntimeException- in case the recorder could not be created
-
newSound
Sound newSound(FileHandle fileHandle)
Creates a new
Soundwhich 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 theFileHandle. 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:
- the new Sound
- Throws:
GdxRuntimeException- in case the sound could not be loaded
-
newMusic
Music newMusic(FileHandle file)
Creates a newMusicinstance 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 theMusic.dispose()method. Music instances are automatically paused whenApplicationListener.pause()is called and resumed whenApplicationListener.resume()is called.- Parameters:
file- the FileHandle- Returns:
- the new Music or null if the Music could not be loaded
- Throws:
GdxRuntimeException- in case the music could not be loaded
-
switchOutputDevice
boolean switchOutputDevice(@Null java.lang.String deviceIdentifier)
Sets a new OutputDevice. The identifier can be retrieved fromgetAvailableOutputDevices(). If null is passed, it will switch to auto.- Parameters:
deviceIdentifier- device identifier to switch to, or null for auto
-
getAvailableOutputDevices
java.lang.String[] getAvailableOutputDevices()
This function returns a list of fully qualified Output device names. This function is only implemented on desktop. On all other platforms it will return a empty array. It will also return a empty array on error. The names returned need os dependent preprocessing before exposing to a user.- Returns:
- A array of available output devices
-
-