Game Development Reference
In-Depth Information
Exploring the Music interface
The Music interface is suitable for playing back long audio files and is designed in
a very similar way when compared with the Sound interface. Therefore, new music
instances can also be requested from LibGDX's Gdx.audio module; however, the
method is called newMusic() , as shown here:
Music music = Gdx.audio.newMusic(Gdx.files.internal("music.mp3"));
The Music interface also makes use of the Disposable interface. The music instances
that are no longer needed should always be disposed to free the allocated memory
as follows:
music.dispose(); // free allocated memory
Apart from this, the interface provides the expected method to control music
playback as follows:
void play();
void pause();
void stop();
Additionally, there are some methods to modify the music being played, as shown
in the following listing:
void setPan(float pan, float volume);
void setVolume(float volume);
void setLooping(boolean isLooping);
At times, it might be useful to query the music for its state, such as its current
position (in milliseconds) and whether it is still playing or not, as follows:
boolean isPlaying();
float getPosition();
Accessing the audio device directly
In addition to the Music and Sound interfaces, LibGDX also provides you with two
more low-level audio interfaces, AudioDevice and AudioRecorder , that enable
direct access to the audio device. They can be used for recording and playback of raw
samples of audio data. These samples are stored as a PCM-encoded audio signal.
 
Search WWH ::




Custom Search