Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 10. Multimedia > Playing audio

10.2. Playing audio

Probably the most basic need for multimedia on a cell phone is the ability to play audio files, whether new ringtones, MP3s, or quick audio notes. Android’s MediaPlayer is easy to use. At a high level, all you need to do to play an MP3 file is follow these steps:

1.
Put the MP3 in the res/raw directory in a project (note that you can also use a URI to access files on the network or via the internet).

2.
Create a new instance of the MediaPlayer, and reference the MP3 by calling MediaPlayer.create().

3.
Call the MediaPlayer methods prepare() and start().


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial