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

11.2. Managing media

The media playback capabilities of Android devices present many intriguing opportunities for developers. But before you can start using those features to play and present any sort of media, you need some media to play. The media that you use can be found in many different places on the device. It might be an integral part of your application and thus bundled with it directly. Alternatively, it could be something that’s not specific to your application—some type of media that belongs to the user. This could be media that the user loaded on the device directly (audio files are a common type). Or it could be media that the user created with the device, such as pictures or videos that the user shot with the device’s camera. In all of these cases, the media will typically be stored on the external storage of the device—the SD card. There are some conventions as to where to store media on the SD card, but the truth is that it could be in a wide variety of places. Fortunately, Android provides a number of ways to find and load media from all of these various sources. Let’s start with the most straightforward situation: loading media from resources or files.

Technique 55: Working with resources and files

Input and output (I/O) are common tasks in most programming languages. This is certainly the case for the Java programming language that Android uses. In some places, Android augments or provides alternatives to what you find in Java. For I/O, you can use most of the Java I/O APIs that you’re used to, and you can use them to load various types of media for playback. In a few places, Android provides some extra convenience methods. Let’s take a look at how to use file I/O to load media.


  

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