-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathexample.js
More file actions
55 lines (51 loc) · 1.82 KB
/
Copy pathexample.js
File metadata and controls
55 lines (51 loc) · 1.82 KB
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
/**
* An example file to learn how iTunes-bridge works
*
* @projectname iTunes-bridge
* @version 0.5.0-beta
* @author AngryKiller
* @copyright 2018
* @license GPL-3.0
*
*/
var iTunes = require('./itunes-bridge');
var currentTrack = iTunes.getCurrentTrack();
// We load the iTunes-bridge emitter to receive events
var iTunesEmitter = iTunes.emitter;
switch(currentTrack.playerState) {
case "playing": {
var exampleMsg = "iTunes is currently playing " + currentTrack.name + " by " + currentTrack.artist + ' from the album "' + currentTrack.album + '". This song is ' + currentTrack.duration + 's long and will finish in ' + currentTrack.remainingTime + 's';
var exampleMsg2 = "You have " + iTunes.getPlaylistCount() + " playlists in your library and " + iTunes.getTrackCount() + " tracks!";
console.log(exampleMsg);
console.log(exampleMsg2);
break;
}
case "paused": {
var exampleMsg = 'iTunes is currently paused';
console.log(exampleMsg);
break;
}
case "stopped": {
var exampleMsg = "iTunes is not playing at the moment.";
console.log(exampleMsg);
break;
}
}
// Do something when iTunes is playing
iTunesEmitter.on('playing', function(type, currentTrack){
// If it is a paused track that restarts playing
if(type === "player_state_change") {
console.log(currentTrack.name + " has been resumed! ");
// Or if it is a new track
}else if(type === 'new_track'){
console.log(currentTrack.name+" is now playing!")
}
});
// Do something when iTunes is paused
iTunesEmitter.on('paused', function(type, currentTrack){
console.log(currentTrack.name+" is now paused!");
});
// Do something when iTunes is stopped
iTunesEmitter.on('stopped', function(){
console.log("iTunes is not longer playing!");
});