-
Notifications
You must be signed in to change notification settings - Fork 11
/
midiplayer.js
54 lines (50 loc) · 1.58 KB
/
midiplayer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var cordova = require('cordova'),
exec = require('cordova/exec');
var exec2 = function (methodName, options, success, error) {
exec(success, error, "MidiPlayer", methodName, options);
};
var MidiPlayer = function () {};
MidiPlayer.prototype = {
getPathFromAsset: function(path) {
if(device.platform == "Android")
{
return "www/"+path;
}
var finalPath = cordova.file.applicationDirectory + "www/" + path;
finalPath = finalPath.substr(7);
return finalPath;
},
setup: function (midiFilePath, programs, success, error, status) {
exec2("setup", [midiFilePath, programs], function (statusValue) {
if (statusValue === "success") {
if (success) {
success();
}
return;
}
if (status) {
status(statusValue);
}
}, error);
},
play: function () {
exec2("play", [], function() { console.log("success play"); }, function(err) { console.log("error play:" + err); });
},
pause: function () {
exec2("pause", [], null, null);
},
stop: function () {
exec2("stop", [], null, null);
},
getCurrentPosition: function (success, error) {
exec2("getCurrentPosition", [], success, error);
},
seekTo: function (position) {
exec2("seekTo", [position], null, null);
},
release: function () {
exec2("release", [], null, null);
}
};
var midiPlayer = new MidiPlayer();
module.exports = midiPlayer;