我很确定这是科尔多瓦的一个错误......
事情是这样的,我们从以下开始:
navigator.notification.beep
这将触发(cordova-1.6.1.js):
beep:function(count) {
(new Media('beep.wav')).play();
}
创建 Media 对象将导致:
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]);
};
如果您查看 Cordova.plist,您会看到插件名称“Media”被映射到“CDVSound”,并且在 CDVSound 中没有方法 create...
而且因为没有“媒体”的“创建”方法,我们得到:
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"]}
那么我们怎么能听到声音呢?
好问题..如果你看:
new Media('beep.wav')).play();
你注意到我们调用了 play(),让我们看看它做了什么:
Media.prototype.play = function(options) {
exec(null, null, "Media", "startPlayingAudio", [this.id, this.src, options]);
};
在 CDVSound.h 中:
- (void) startPlayingAudio:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;