In today's post we will discuss about media plugin for Cordova apps. This plugin allows to record and play back audio files on a device. This plugin defines media constructor. We need to use this plugin with the device ready event. As it is not available after device ready event.
Now we will move to the installation part:
We can install the plugin through CLI simple run:
$ cordova plugin add cordova-plugin-media
This plugin support following platforms:
Window phone7 and 8
The next step is how we can use the plugin in our application:
var media = new Media(src, mediaSuccess, [mediaError], [mediaStatus]);
In the above, We are using some parameters.
src contains the URI of the audio.
mediasuccess is a callback function which fires when media object finished the action i.e play, record and stop. It is an optional function.
mediaerror is callback function and works when any error occurs. It is an optional function.
mediastatus works when the user changes the status. It is an optional function. Following are the constant when user changes the status: