To play longer audio files, you can use the MediaPlayer component. But with shorter sounds where the file is less than 1 megabyte in size, you can play the file with SoundPool. This class can load a file directly from assets, so you don’t have to take the step of copying it to a new location. And you can cache the file in memory as an activity starts up so you won’t have any latency the first time you play it. This make SoundPool ideal for game sounds and other effects that have to be played multiple times.
- [Instructor] In a previous tip,…I described how to play a long running sound…that's packaged as an app asset with media player.…I showed how to copy the file from the assets directory…to internal storage, and then play the file from there.…With shorter sounds, where the file…is less than one megabyte in size,…you can play the file with SoundPool.…The SoundPool class can load a file directly from assets,…so you don't have to take the step…of copying it to a new location.…And you can cache the file in memory,…as an activity starts up, so you won't have any latency…the first time you play it.…
This makes SoundPool ideal for game sounds,…and other effects that have to be played multiple times.…In this starting project, in the assets directory,…I've included two wave files.…They're short files,…and they're each less than one megabyte in size,…so they're ideal for demonstrating the SoundPool class.…In the main activity class,…I'll declare a couple of private fields.…The first will be an instance of the SoundPool class,…
Skill Level Intermediate
Q: Why can't I earn a Certificate of Completion for this course?
A: We publish a new tutorial or tutorials for this course on a regular basis. We are unable to offer a Certificate of Completion because it is an ever-evolving course that is not designed to be completed. Check back often for new movies.