Skip to content Skip to sidebar Skip to footer

Phonegap Media Api (android) - Media Is Not Defined

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 Ref

Solution 1:

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>

Post a Comment for "Phonegap Media Api (android) - Media Is Not Defined"