-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodMusic.vb
189 lines (169 loc) · 6.96 KB
/
modMusic.vb
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
Imports WMPLib
Module modMusic
Dim WithEvents MusicPlayer As WMPLib.WindowsMediaPlayer
Dim isPaused As Boolean
Dim isPlaying As Boolean
Dim strNowPlaying As String
Dim strNowPlayingArtist As String
Dim strPrevPlaying As String
Public Function Disable() As String
Unload()
My.Settings.Music_Enable = False
My.Application.Log.WriteEntry("Music module is disabled")
Return "Music module disabled"
End Function
Public Function Enable() As String
My.Settings.Music_Enable = True
My.Application.Log.WriteEntry("Music module is enabled")
Load()
Return "Music module enabled"
End Function
Public Function Load() As String
If My.Settings.Music_Enable = True Then
My.Application.Log.WriteEntry("Loading music module")
MusicPlayer = New WMPLib.WindowsMediaPlayer
MusicPlayer.settings.autoStart = True
MusicPlayer.settings.setMode("loop", True)
MusicPlayer.settings.setMode("shuffle", True)
MusicPlayer.settings.volume = My.Settings.Music_Volume
MusicPlayer.uiMode = "invisible"
Return "Music module loaded"
Else
My.Application.Log.WriteEntry("Music module is disabled, module not loaded")
Return "Music module is disabled, module Not loaded"
End If
End Function
Private Sub MusicPlayer_MediaError(ByVal pMediaObject As Object) Handles MusicPlayer.MediaError
My.Application.Log.WriteEntry("Cannot play media file", TraceEventType.Warning)
End Sub
Private Sub MusicPlayer_PlayStateChange() Handles MusicPlayer.CurrentItemChange
If MusicPlayer.currentMedia.getItemInfo("Title") <> strPrevPlaying Then
strPrevPlaying = strNowPlaying
strNowPlaying = MusicPlayer.currentMedia.getItemInfo("Title")
strNowPlayingArtist = MusicPlayer.currentMedia.getItemInfo("Artist")
My.Application.Log.WriteEntry("Now playing " + strNowPlaying + " by " + strNowPlayingArtist)
modMatrixLCD.ShowNotification(strNowPlaying, strNowPlayingArtist)
End If
End Sub
Public Sub PauseMusic()
If isPlaying = True Then
MusicPlayer.controls.pause()
isPlaying = False
isPaused = True
End If
End Sub
Public Function PlayAlbum(ByVal strAlbumName As String) As String
Dim oQuery As Object
oQuery = MusicPlayer.mediaCollection.createQuery()
oQuery.AddCondition("Album", "Contains", strAlbumName)
MusicPlayer.currentPlaylist = MusicPlayer.mediaCollection.getPlaylistByQuery(oQuery, "audio", "", False)
If MusicPlayer.currentPlaylist.count > 0 Then
isPlaying = True
Return "Playing songs from " + strAlbumName
Else
isPlaying = False
Return "No results for that album"
End If
End Function
Public Function PlayArtist(ByVal strArtistName As String) As String
Dim oQuery As Object
oQuery = MusicPlayer.mediaCollection.createQuery()
oQuery.AddCondition("Author", "Contains", strArtistName)
MusicPlayer.currentPlaylist = MusicPlayer.mediaCollection.getPlaylistByQuery(oQuery, "audio", "", False)
If MusicPlayer.currentPlaylist.count > 0 Then
isPlaying = True
Return "Playing some " + strArtistName
Else
isPlaying = False
Return "No results for that artist"
End If
End Function
Public Function PlayGenre(ByVal strGenre As String) As String
Dim oQuery As Object
oQuery = MusicPlayer.mediaCollection.createQuery()
oQuery.AddCondition("Genre", "Contains", strGenre)
MusicPlayer.currentPlaylist = MusicPlayer.mediaCollection.getPlaylistByQuery(oQuery, "audio", "", False)
If MusicPlayer.currentPlaylist.count > 0 Then
isPlaying = True
Return "Playing some " + strGenre + " music"
Else
isPlaying = False
Return "No results for that genre"
End If
End Function
Public Sub PlayNext()
If isPlaying = True Then
MusicPlayer.controls.next()
End If
End Sub
Public Function PlayPlaylist(ByVal strPlaylistName As String) As String
Try
MusicPlayer.currentPlaylist = MusicPlayer.playlistCollection.getByName(strPlaylistName).Item(0)
isPlaying = True
My.Settings.Music_LastPlaylist = strPlaylistName
Return "Playing " + strPlaylistName
Catch ArgExcep As System.ArgumentException
isPlaying = False
My.Application.Log.WriteException(ArgExcep)
Return "Unable to locate playlist"
Catch NotFoundExcep As System.IO.FileNotFoundException
isPlaying = False
My.Application.Log.WriteException(NotFoundExcep)
Return "Invalid playlist file location in library"
End Try
End Function
Public Sub PlayPrevious()
If isPlaying = True Then
MusicPlayer.controls.previous()
End If
End Sub
Public Function PlaySong(ByVal strSongName As String) As String
Dim oQuery As Object
oQuery = MusicPlayer.mediaCollection.createQuery()
oQuery.AddCondition("Title", "Contains", strSongName)
MusicPlayer.currentPlaylist = MusicPlayer.mediaCollection.getPlaylistByQuery(oQuery, "audio", "", False)
If MusicPlayer.currentPlaylist.count > 0 Then
isPlaying = True
Return "Playing " + strSongName
Else
isPlaying = False
Return "No results for that song"
End If
End Function
Public Sub ResumeMusic()
If isPaused = True Then
MusicPlayer.controls.play()
isPaused = False
isPlaying = True
End If
End Sub
Public Sub SetVolume(ByVal intValue As Integer)
If isPlaying = True AndAlso intValue >= 0 AndAlso intValue <= 100 Then
MusicPlayer.settings.volume = intValue
My.Settings.Music_Volume = intValue
End If
End Sub
Public Function ShowAlbum() As String
If isPlaying = True Then
Dim strAlbum As String = MusicPlayer.currentMedia.getItemInfo("Album")
Dim strAlbumArtist As String = MusicPlayer.currentMedia.getItemInfo("AlbumArtist")
modMatrixLCD.ShowNotification(strAlbum, strAlbumArtist)
Return "This song is from " & strAlbum & " by " & strAlbumArtist
Else
Return "Not currently playing music"
End If
End Function
Public Sub StopMusic()
If isPlaying = True Then
MusicPlayer.controls.stop()
isPlaying = False
End If
End Sub
Public Function Unload() As String
My.Application.Log.WriteEntry("Unloading music module")
If MusicPlayer IsNot Nothing Then
MusicPlayer.close()
End If
Return "Music module unloaded"
End Function
End Module