Playing sounds
The technique presented to play BGM from a MIME source is very practical but, sadly, not flexible enough. Recreating an AudioPlayer object is not necessary and accessing asset files each time is not good in terms of efficiency.
So, when it comes to playing sounds quickly in response to an event and generating them dynamically, we need to use a sound buffer queue. Each sound is preloaded or generated in a memory buffer, and placed into a queue when the playback is requested. No need to access a file at runtime!
A sound buffer, in the current OpenSL ES Android implementation, can contain PCM data. Pulse Code Modulation (PCM) is a data format dedicated to the representation of digital sounds. It is the format used in CD and in some Wave ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access