Let's create an audio node in the simpleInitApp()
method, and play it:
Make a copy of
Main.java
and name the classBackgroundSounds.java
. Remember to also refactor the first line of themain()
method toBackgroundSounds app = new BackgroundSounds();
.Copy the
River.ogg
sound file into theassets/Sounds/Environment/
directory.Use the
simpleInitApp()
method to load the sound into an audio node:public void simpleInitApp() { AudioNode natureAudio = new AudioNode( assetManager, "Sounds/Environment/River.ogg");
Specify properties of the sound; for example, set the volume to
5
.10
is loudest,0
is silent.natureAudio.setVolume(5);
Switch the sound to play continuously by setting the looping property to
true
. Note that if you ran the application now, you would not hear anything yet.natureAudio.setLooping(true);
Call the
play()
method on theAudioNode
to start playing the sound:natureAudio.play(); }
Run the application. You should hear the continuous sound of a river...