Chapter 9

Media

WHAT YOU WILL LEARN IN THIS CHAPTER:

  • Working with media files
  • Using the Media object
  • Using Media methods
  • Handling errors

In the past few chapters, you have learned how to use the accelerometer, the compass, and geolocation services. In this chapter, you learn how to use the device’s built-in media services.

LEARNING ABOUT MEDIA FILES

In this section, you learn what the Media API is and what services are available to you to use media files.

What Are Media Files?

The Media API lets you record and play back audio on a device. You can typically play audio files loaded locally on the device, or play audio files retrieved from the Internet.

Image

NOTE An important thing to remember is that the current PhoneGap implementation doesn’t adhere to World Wide Web Consortium (W3C) specifications for media capture, and any future implementations may deprecate the current APIs. Furthermore, the Media API is compatible only with Android and iOS devices.

Using Media Files

Being able to play music or other audio files directly from your smartphone is quite convenient. For example, if you’re on a long trip and don’t have a book handy, no problem, you can listen to an audio book.

Furthermore, the capability to record audio has been pretty convenient, too. If you’re waiting for a meeting to start, and need to record a few reminders for later, you could use your device as a memo recorder. ...

Get Beginning PhoneGap now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.