O'Reilly logo

Libgdx Cross-platform Game Development Cookbook by Alberto Cejas Sánchez, David Saltares Márquez

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Audio streaming for background music

The Sound interface gives us a great deal of flexibility. However, it's not suitable for all needs due to one fundamental reason: sounds are fully loaded in memory before playback can start. This is not a problem for short effects, but it rapidly becomes one if we try to use it to play our soundtracks, especially in memory-limited devices such as phones. While effects lie around the order of tens to hundreds of KB, reasonably decent-quality song files can take up around 10 MB, even if they are not very long.

How do we solve this dire situation? Streaming is the answer. This technique only needs to keep in memory the next chunk of file that needs to be played, which makes for an epic win. However, not everything ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required