Try the following code to see the difference between the two ways of loading audio files. Use the Boolean parameter in the AudioNode
constructor to switch streaming on (true
) or off (false
).
Make a copy of
Main.java
and name the classBufferedVsStreamed.java
. Remember to also refactor the first line of themain()
method toBufferedVsStreamedapp = new BufferedVsStreamed();
.Nature.ogg
is a large file (650 kb), so you decide to stream it using the following code:public void simpleInitApp() { AudioNode natureAudio = new AudioNode(assetManager,"Sounds/Environment/Nature.ogg", true); // streaming=true natureAudio.setVolume(5); natureAudio.play(); // play as stream
Footsteps.ogg
is a small file (25 kb), so you decide to pre-buffer it using the following code:AudioNode stepsAudio = new AudioNode(assetManager,"Sounds/Effects/Footsteps.ogg", false); // streaming=false stepsAudio.setVolume(2); stepsAudio.setLooping(true); stepsAudio.play(...