Eror plugin is not defined (cordova-plugin-media)

hi, I have tried to build Ionic recorder, I user cordova-plugin-media and it’s installed successfully at command prompt, but “Media”(var mediaRec = new Media(src) in my controller is not defined

here is my controller :

$scope.recordAudio = function() {
    var src = "mymedia.mp3";
    var mediaRec = new Media(src,
        // success callback
        function() {
            console.log("recordAudio():Audio Success");

        // error callback
        function(err) {
            console.log("recordAudio():Audio Error: "+ err.code);

    // Record audio

     // Stop recording after 10 seconds
    setTimeout(function() {
    }, 10000);

// Play audio
$scope.playAudio=function(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;

I have tried to add that plugin again, I have tried to update the cordova, but it’s does not work.
here is my eror :

if someone know what should I do, please help~
thanks :blush:

Have you tried it on device ready?

Although in the global scope, it is not available until after the deviceready event.

Yes, I have tried this in my phone but work nothing :pensive:

did you tried with platform ready or device ready?

Not yet :joy: oke I will try now !!! :grin:

I had the same problem this morning , but in my case was because the developer has deployed a new version of the plugin that was not compatible with android < 5.0 ,
i found “ionic plugin add cordova-plugin-media@1.0.1” to work fine.
Also remember that all cordova plugins all available after that the deviceready is trigged

1 Like