Phonegap Media API (Android) - Media is not defined
android, cordova, jquery, webview
Solution
You might be trying to call `Media` before the deviceready event fires.
<script type="text/javascript">
var myMedia = null;
document.addEventListener("deviceready",onDeviceReady,false);
function onDeviceReady () {
myMedia = new Media("/android_asset/www/one.mp3",
function(){
if (myMedia) {
myMedia.stop();
myMedia.release();
}
},
function(error){
console.log(error.message);
}
);
}
$(document).ready(function(){
$('.one').click(function(event){
myMedia.play();
});
});
</script>
Problem
I want to build a Android WebView app, which plays a sound when the user presses a button.For some reason I can't get the PhoneGap media API to work. It keep showing: ``` Uncaught ReferenceError: Media is not defined at file:///android_asset/www/script.js:3 ``` Here is my code: ``` $(document).ready(function(){ var myMedia = new Media("/android_asset/www/one.mp3"); $('.one').click(function(){ myMedia.play(); }); }); ``` Anyone know how to fix this problem?