Book Image

PhoneGap 4 Mobile Application Development Cookbook

Book Image

PhoneGap 4 Mobile Application Development Cookbook

Overview of this book

Table of Contents (19 chapters)
PhoneGap 4 Mobile Application Development Cookbook
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Preface
Index

Playing audio files from the local filesystem or over HTTP


PhoneGap and the media plugin API provide 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 to it the location of the audio file we want to play back:

  1. Firstly, create a new PhoneGap project named audioplaying by running the following command:

    phonegap create audioplaying com.myapp.audioplaying audioplaying
    
  2. Add the device's platform. You can choose to use Android, iOS, or both:

    cordova platform add ios
    cordova platform add android
    
  3. Add the media and file-transfer plugins by running the following commands:

    cordova plugin add org.apache.cordova.media
    cordova plugin add org.apache.cordova.file-transfer
    
  4. Open www/index.html...