Book Image

PhoneGap 3.x Mobile Application Development HOTSHOT

By : Kerri Shotts
Book Image

PhoneGap 3.x Mobile Application Development HOTSHOT

By: Kerri Shotts

Overview of this book

<p>PhoneGap allows you to use your existing knowledge of HTML, CSS, and JavaScript to create useful and exciting mobile applications.<br /><br />This book will present you with 12 exciting projects that will introduce you to the dynamic world of app development in PhoneGap. Starting with their design and following through to their completion, you will develop real-world mobile applications. Each app uses a combination of core PhoneGap technologies, plugins, and various frameworks covering the necessary concepts you can use to create many more great apps for mobile devices.</p>
Table of Contents (21 chapters)
PhoneGap 3.x Mobile Application Development HOTSHOT
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Covering the Media API


In this task, you'll be introduced to the Media API and will create a class that our audio notes can use to interact with the Media API. We'll call this a media manager.

Getting ready

Before going any further, you should add the Media plugin to the project:

cordova plugin add org.apache.cordova.media

Although we'll be covering the majority of the Media API, it's always best to consult the Cordova documentation to ensure you're seeing the most up-to-date information. You should be able to see the documentation on the Media API at https://github.com/apache/cordova-plugin-media/blob/dev/doc/index.md.

Getting on with it

As with the File API, the Media API is based on callbacks, though thankfully, not to the same extent. We can interact with most of the API in a synchronous fashion, but there are a few areas that work asynchronously.

To instantiate a Media object, you can do the following:

var myMedia = new Media ( pathToFile, success, error, status );

Let's look at each of these...