我找到this cordova module,虽然没有使用说明?
写作
MusicPlayer.init(
function (msg) {
console.log("audio completed"+ msg);
},
// error callback
function (e) {
console.log("Error getting message=" + e);
}
);
返回Could not load main module: ReferenceError: MusicPlayer is not defined
模块的导出方式与module.exports = new MusicPlayer();
类似,所以调用它的方式就是它自己吗?
尝试,window.cordova.plugins.Musicplay.init();
也犯了同样的错误。
调用此模块并在cordova中使用的正确方法是什么?
编辑 - 这是函数的定义方式
var exec = require('cordova/exec');
function MusicPlayer() {}
MusicPlayer.prototype.init = function(successCallback, errorCallback, json) {
exec(successCallback, errorCallback, "MusicPlayer", "init", [json]);
};
MusicPlayer.prototype.getMusicList = function(successCallback, errorCallback, json) {
exec(successCallback, errorCallback, "MusicPlayer", "getMusicList", [json]);
};
..
..
module.exports = new MusicPlayer();
答案 0 :(得分:1)
检查clobbers目标:https://github.com/jasminpethani/cordova-plugin-musicplayer/blob/master/com.srini.musicplayer/plugin.xml#L14-L16
<js-module src="www/musicplayer.js" name="musicplayer">
<clobbers target="musicplayer" />
</js-module>
因此实例名称应为musicplayer
musicplayer.init(function (msg) {
console.log("audio completed"+ msg);
},
// error callback
function (e) {
console.log("Error getting message=" + e);
});
提示:
MusicPlayer
$ cordova plugin list
插件
请务必在内部致电musicplayer.init
:
document.addEventListener("deviceready", function(){/**/}