Playing Media

To get started, we'll show you how to build a simple application that plays an MP3 file located on the Web (see Figure 24–3). After that, we will talk about using the setDataSource() method of the MediaPlayer class to play content from the .apk file or the SD card. MediaPlayer isn't the only way to play audio, though, so we'll also cover the SoundPool class, as well as JetPlayer, AsyncPlayer, and, for the lowest level of working with audio, the AudioTrack class. After that, we will discuss some of the shortfalls of the MediaPlayer class. Finally, we'll see how to play video content.

Playing Audio Content

Figure 24–3 shows the user interface for our first example. This application will demonstrate some of the fundamental uses of ...

Get Pro Android 4 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.