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.
Android App Development: Communicating with the Userwith Joe Marini1h 12m Intermediate
Building Android Apps with Cloud Serviceswith Albert Lo2h 37m Intermediate
Android App Development: Data Persistence Librarieswith Annyce Davis4h 52m Intermediate
New This Week:
1. Android Development Tips Weekly
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.