O'Reilly logo

PhoneGap Mobile Application Development Cookbook by Matt Gifford

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Playing audio files from the local filesystem or over HTTP

The PhoneGap API provides us with a relatively straightforward process to play back audio files. These can be files stored within the application's local filesystem, bundled with the application, or over remote files accessible by a network connection. Wherever the files may be, the method of playback is achieved in exactly the same way.

How to do it...

We must create a new Media object and pass into it the location of the audio file we want to play back:

  1. Create the initial layout for the HTML, and include the relevant references to the JavaScript and style sheets. In this example we are going to be using the jQuery Mobile framework (http://jquerymobile.com/):
    <!DOCTYPE HTML> <html> <head> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required