The following is the first few sections of a chapter from The Busy Coder's Guide to Android Development, plus headings for the remaining major sections, to give you an idea about the content of the chapter.
Whether it comes in the form of simple beeps or in the form
of symphonies (or gangster rap or whatever), Android applications
often need to play audio. A few things in Android can play audio
automatically, such as a
once you get past those, you are on your own.
Fortunately for you, Android offers support for audio playback, and we will examine some of the options in this chapter.
Understanding this chapter requires that you have read the core chapters of this book.
In Android, you have a few different places you can pull media clips from — one of these will hopefully fit your needs:
res/raw/in your project), so they are bundled with your application. The benefit is that you’re guaranteed the clips will be there; the downside is that they cannot be replaced without upgrading the application.
assets/in your project) and reference them via
file:///android_asset/URLs in a
Uri. The benefit over raw resources is that this location works with APIs that expect
Uriparameters instead of resource IDs. The downside — assets are only replaceable when the application is upgraded — remains. On the whole, the audio APIs tend to favor raw resources over assets.
The preview of this section was lost in the sofa cushions.
The preview of this section is en route to Mars.