5

I'm trying to play a sound file with PhoneGap/Cordova 1.6.0. When I play the sound I get these errors:

ERROR: Method 'create:withDict:' not defined in Plugin 'Media'
FAILED pluginJSON = {"className":"Media","methodName":"create","arguments":["INVALID","94671882-85c3-9173-17a2-ed166310d77d","beep.wav"]}

Even though I get these error messages the sound plays in the Simulator, but not on my device (iPad 2 5.1). I've tried with both navigator.notification.beep and new Media() but they both throw the same error.

Does anyone know how to solve this issue?

4

2 に答える 2

0

I experienced this error when my fourth parameter of PhoneGap.exec() didn't match my Objective-C method name.

Verify that the "methodName" described in the error message, in fact, exists in your Objective-C implementation.

于 2012-04-18T05:27:11.083 に答える
0

I'm pretty sure it's a bug in Cordova...

Here is how it goes, we start with:

navigator.notification.beep

that will trigger (cordova-1.6.1.js):

beep:function(count) {
        (new Media('beep.wav')).play();
    }

Creating the Media object will result in:

var Media = function(src, successCallback, errorCallback, statusCallback) {

// successCallback optional
if (successCallback && (typeof successCallback !== "function")) {
    console.log("Media Error: successCallback is not a function");
    return;
}

// errorCallback optional
if (errorCallback && (typeof errorCallback !== "function")) {
    console.log("Media Error: errorCallback is not a function");
    return;
}

// statusCallback optional
if (statusCallback && (typeof statusCallback !== "function")) {
    console.log("Media Error: statusCallback is not a function");
    return;
}

this.id = utils.createUUID();
mediaObjects[this.id] = this;
this.src = src;
this.successCallback = successCallback;
this.errorCallback = errorCallback;
this.statusCallback = statusCallback;
this._duration = -1;
this._position = -1;
exec(null, this.errorCallback, "Media", "create", [this.id, this.src]);
};

If you look at Cordova.plist you will see that the plugin name "Media" is mapped to "CDVSound" and in CDVSound there is no method create...

And because there is no method "create" for "Media" we get:

cleanApp[24713:707] ERROR: Method 'create:withDict:' not defined in Plugin 'Media'
cleanApp[24713:707] FAILED pluginJSON = {"className":"Media","methodName":"create","arguments":["INVALID","b6acfbad-1e26-de77-1557-0d7c2f87a00a","beep.wav"]}

So how come we can hear the sound?

good question.. if you look at:

new Media('beep.wav')).play();

You notice that we call play(), let's see what that does:

Media.prototype.play = function(options) {
    exec(null, null, "Media", "startPlayingAudio", [this.id, this.src, options]);
};

in CDVSound.h:

- (void) startPlayingAudio:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
于 2012-05-30T12:38:20.000 に答える