I have been searching everywhere and trying everything, but I just can't seem to be able to use cordova's Media plugin. (e.g var sound = new Media("sound.mp3");
)
I've tried everything and can't seem to get it to work. Please put me out of my misery and give me a step by step instruction on how to do this. I have android sdk and gethub installed already along with a bunch of other things.
Most of the things I see are, " Installation: cordova plugin add cordova-plugin-media
" THATS IT. Specially the ones with the stupid $ symbol which is completely unrecognized.
..thank you in advance :(
At first double check your work: Step1, Step2 Then, to add media plugin to your project you need to:
(in app/res/xml/config.xml)
<feature name="Media">
<param name="android-package" value="org.apache.cordova.media.AudioHandler" />
</feature>
(in app/AndroidManifest.xml)
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
And this is a code sample of how to use it (source)
// Play audio
//
function playAudio(url) {
// Play the audio file at url
var my_media = new Media(url,
// success callback
function () {
console.log("playAudio():Audio Success");
},
// error callback
function (err) {
console.log("playAudio():Audio Error: " + err);
}
);
// Play audio
my_media.play();
}
Finally, you can call the playAudio('path/to/file.mp3') function within your code (after device got ready).
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
console.log(Media);
/* call function here */
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments