forked from homerours/cordova-music-controls-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMusicControls.js
59 lines (53 loc) · 1.67 KB
/
MusicControls.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
55
56
57
58
59
module.exports = {
updateCallback: function () {},
create: function (data, successCallback, errorCallback) {
if (data.artist === undefined) {
data.artist = '';
}
if (data.track === undefined) {
data.track = '';
}
if (data.cover === undefined) {
data.cover = '';
}
if (data.ticker === undefined) {
data.ticker = '';
}
if (data.isPlaying === undefined) {
data.isPlaying = true;
}
if (data.hasPrev === undefined) {
data.hasPrev = true;
}
if (data.hasNext === undefined) {
data.hasNext = true;
}
if (data.hasClose === undefined) {
data.hasClose = false;
}
if (data.dismissable === undefined) {
data.dismissable = false;
}
cordova.exec(successCallback, errorCallback, 'MusicControls', 'create', [data]);
},
updateIsPlaying: function (isPlaying, successCallback, errorCallback) {
cordova.exec(successCallback, errorCallback, 'MusicControls', 'updateIsPlaying', [{isPlaying: isPlaying}]);
},
destroy: function (successCallback, errorCallback) {
cordova.exec(successCallback, errorCallback, 'MusicControls', 'destroy', []);
},
// Register callback
subscribe: function (onUpdate) {
module.exports.updateCallback = onUpdate;
},
// Start listening for events
listen: function () {
cordova.exec(module.exports.receiveCallbackFromNative, function (res) {
}, 'MusicControls', 'watch', []);
},
receiveCallbackFromNative: function (messageFromNative) {
module.exports.updateCallback(messageFromNative);
cordova.exec(module.exports.receiveCallbackFromNative, function (res) {
}, 'MusicControls', 'watch', []);
}
};