6de93c1b8b96c168beb3a890291c7d4c063018aa
[smartthings-infrastructure.git] / MusicPlayer / MusicPlayer.groovy
1 //Create a class for music player
2 package MusicPlayer
3 import Timer.SimulatedTimer
4
5
6 public class MusicPlayer {
7         private String id
8         private String label
9         private String displayName
10         private int level
11         private String mute
12         private String status
13         private int trackNumber
14         private List trackData
15         
16         MusicPlayer(String id, String label, String displayName, int level, String mute, String status, int trackNumber, List trackData) {
17                 this.id = id
18                 this.label = label
19                 this.displayName = displayName
20                 this.level = level
21                 this.mute = mute
22                 this.status = status
23                 this.trackNumber = trackNumber
24                 this.trackData = trackData
25         }
26
27         //methods
28         def mute() {
29                 println("the music player with id:$id is muted!")
30                 this.mute = "muted"
31         }
32         def nextTrack() {
33                 if (trackNumber != trackData.size()-1)
34                         trackNumber = trackNumber+1
35                 else
36                         trackNumber = 0
37                 def trackPlaying = trackData[trackNumber] 
38                 println("the $trackPlaying is selected!")
39                 this.status = "playing"
40         }
41         def pause() {
42                 println("the music player with id:$id is paused!")
43                 this.status = "paused"
44         }
45         def play() {
46                 println("the music player with id:$id is starting to play!")
47                 this.status = "playing"
48         }
49         def playTrack(String trackToPlay) {
50                 trackNumber = list.indexOf(trackToPlay)
51                 def trackPlaying = trackData[trackNumber]
52                 println("the $trackPlaying is selected to play!")
53                 this.status = "playing"
54         }
55         def previousTrack() {
56                 if (trackNumber != 0)
57                         trackNumber = trackNumber-1
58                 else
59                         trackNumber = trackData.size()-1
60                 def trackPlaying = trackData[trackNumber] 
61                 println("the $trackPlaying is selected!")
62                 this.status = "playing"
63         }
64         /*def restoreTrack(String trackToRestore) {
65                 musicPlayers*.restoreTrack(trackToRestore)
66         }*/
67         def resumeTrack(String trackToResume) {
68                 trackNumber = list.indexOf(trackToResume)
69                 def trackPlaying = trackData[trackNumber]
70                 println("the $trackPlaying is resumed!")
71                 this.status = "playing"
72         }
73         def setLevel(int level) {
74                 this.level = level
75                 println("the level of sound is changed to $level!")
76         }
77         def setTrack(String trackToSet) {
78                 trackNumber = list.indexOf(trackToSet)
79                 def trackPlaying = trackData[trackNumber]
80                 println("the $trackPlaying is set!")
81                 this.status = "playing"
82         }
83         def stop() {
84                 println("the music player with id:$id is stopped!")
85                 this.status = "stopped"
86         }
87
88         def currentValue(String deviceFeature) {
89                 if (deviceFeature == "musicPlayer") {
90                         return status
91                 }
92         }
93 }