-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAudio Go.hta
465 lines (390 loc) · 16.7 KB
/
Audio Go.hta
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
<html lang="en">
<head>
<title>Audio Go</title>
<meta http-equiv="x-ua-compatible" content="IE=9"/>
<link rel="stylesheet" type="text/css" href="Data/css/app-stylesheet.css">
<HTA:APPLICATION ID="AudioGo" APPLICATIONNAME="Audio Go" ICON="Data\ico\AppIcon.ico" BORDER="Dialog" CAPTION="Yes"
SCROLL="No" SHOWINTASKBAR="Yes" SINGLEINSTANCE="Yes" SYSMENU="Yes" WINDOWSTATE="Normal" MaximizeButton="No">
</head>
<object class="WMP" id="WMPlayer"
classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6">
</object>
<script language="VBScript">
' Resize the window
Window.ResizeTo 392, 190 ' false x, true y
' Create the needed objects
Dim Shell : Set Shell = CreateObject("Shell.Application")
' if the dat files are missing replace them
Set FSO = CreateObject("Scripting.FileSystemObject")
' Replace Bindings.dat
If Not FSO.FileExists(".\Data\dat\Bindings.dat") Then
Set File = FSO.CreateTextFile(".\Data\dat\Bindings.dat", 2)
File.Write "close 27" & vbCrLf & "pause 32" & vbCrLf & "loop 82" & vbCrLf & "minus 37" & vbCrLf & "plus 39" & vbCrLf & "up 38" & vbCrLf & "down 40" & vbCrLf & "skip 17"
End If
'Create the Audio Player Object
' Dim oPlayer: Set oPlayer = CreateObject("WMPlayer.OCX")
Dim oPlayer : Set oPlayer = document.getElementById("WMPlayer")
Dim oPlaylist : Set oPlaylist = oPlayer.newPlaylist("AudioGoPlaylist", "")
Dim oSongArray : oSongArray = Array()
playlistName = ""
' Create the vars
hasLoaded = false
hasScrollbar = false
hasChangedScrollbarPadding = false
started = false
isPlaying = false
musicTarget = "" ' "Song" or "Playlist"
isLooping = false
pressedSpace = false
pressedR = false
isPressingSkip = false
startVolume = 50
' Bindings
Key_close = CInt(Read(".\Data\dat\Bindings.dat", "close"))
Key_pause = CInt(Read(".\Data\dat\Bindings.dat", "pause"))
Key_loop = CInt(Read(".\Data\dat\Bindings.dat", "loop"))
Key_minus = CInt(Read(".\Data\dat\Bindings.dat", "minus"))
Key_plus = CInt(Read(".\Data\dat\Bindings.dat", "plus"))
Key_up = CInt(Read(".\Data\dat\Bindings.dat", "up"))
Key_down = CInt(Read(".\Data\dat\Bindings.dat", "down"))
Key_skip = CInt(Read(".\Data\dat\Bindings.dat", "skip"))
' Pause States
Const StatePause = ".\Data\png\PlayIcon.png"
Const StatePlay = ".\Data\png\PauseIcon.png"
' Skip States
Const StatePlusSkip = ".\Data\png\+TimeSkipIcon.png"
Const StatePlusNoSkip = ".\Data\png\+TimeIcon.png"
Const StateMinusSkip = ".\Data\png\-TimeSkipIcon.png"
Const StateMinusNoSkip = ".\Data\png\-TimeIcon.png"
' Loop States
Const StateNoLoop = ".\Data\png\NoLoopIcon.png"
Const StateLoop = ".\Data\png\LoopIcon.png"
' Volume States
Const StateMinusVolume = ".\Data\png\-VolumeIcon.png"
Const StateMinVolume = ".\Data\png\-MinVolumeIcon.png"
Const StatePlusVolume = ".\Data\png\+VolumeIcon.png"
Const StateMaxVolume = ".\Data\png\+MaxVolumeIcon.png"
' is called when a song is chosen
Sub StartUp
oPlayer.settings.autoStart = false
If document.getElementById("mp3Selector").value <> "" AND musicTarget = "Song" Then
SongPath = document.getElementById("mp3Selector").value
oPlayer.URL = SongPath
Else If document.getElementById("mp3folderselector").value <> "" AND musicTarget = "Playlist" Then
SongPath = document.getElementById("mp3folderselector").value
CreatePlaylist SongPath
oPlayer.currentPlaylist = oPlaylist
Else
Exit Sub
End If
started = true
oPlayer.settings.volume = startVolume
If isLooping = True Then
isLooping = False
ToggleLoop
End If
End If
End Sub
Function WMPlayer_CurrentItemChange(change) ' change is nothing
If started = true Then
' clear text
document.getElementById("mp3text").innerHTML = ""
' add the song text
document.getElementById("mp3text").innerHTML = playlistName & " | " & oPlayer.currentmedia.name
End If
End Function
' to read in memory
Function Read(Path, Var)
Set FSO = CreateObject("Scripting.FileSystemObject")
Set File = FSO.OpenTextFile(Path, 1) ' 1 = reading, 2 = write, 8 = write at the end
allData = File.readall
File.Close
For Each ln In Split(allData, vbCrLf)
VarName = Split(ln, " ", 2)(0)
If VarName = Var Then
output = Split(ln, " ", 2)(1)
Exit For
End If
Next
' memory management (vbs does not have one for objects only vars have one)
Set File = Nothing
Set FSO = Nothing
' return
Read = output
End Function
Function GetLastVar(Path)
Set FSO = CreateObject("Scripting.FileSystemObject")
Set File = FSO.OpenTextFile(Path, 1) ' 1 = reading, 2 = write, 8 = write at the end
If FSO.GetFile(Path).Size = 0 Then ' if the file is empty
GetLastVar = ""
Exit Function
End If
allData = File.readall
File.Close
If Split(allData, vbCrLf)(UBound(Split(allData, vbCrLf))-1) = "" Then ' if last line is empty
GetLastVar = ""
Exit Function
End If
VarName = Split(Split(allData, vbCrLf)(UBound(Split(allData, vbCrLf))-1), " ", 2)(0) ' get the last var (UBound = last index)
' memory management (vbs does not have one for objects only vars have one)
Set File = Nothing
Set FSO = Nothing
' return
GetLastVar = VarName
End Function
' to write in memory
Sub WriteVar(Path, Var, Text)
Set FSO = CreateObject("Scripting.FileSystemObject")
Set File = FSO.OpenTextFile(Path, 1) ' 1 = reading, 2 = write, 8 = write at the end
PathOver = Split(Path, "\")
i = -1
For each x in PathOver
i = i+1
Next
PathOverwrite = ""
y = -1
For each x in PathOver
y = y+1
If Not y = i Then
PathOverwrite = PathOverwrite & x & "\"
Else
PathOverwrite = PathOverwrite & "temp.dat"
End If
Next
Set FileOver = FSO.CreateTextFile(PathOverwrite, 2) ' 1 = reading, 2 = write, 8 = write at the end
Do While Not File.AtEndofStream
ln = File.ReadLine
If ln <> "" Then
VarName = Split(ln, " ", 2)(0)
End If
If VarName = Var Then
FileOver.WriteLine Var & " " & Text
added = true
Else
FileOver.WriteLine ln
End If
Loop
If added <> true Then
FileOver.WriteLine Var & " " & Text
End If
File.Close
FileOver.Close
Set FileOver = FSO.OpenTextFile(PathOverwrite, 1)
Set File = FSO.OpenTextFile(Path, 2)
File.Write ""
If FSO.GetFile(PathOverwrite).Size <> 0 Then
text = FileOver.ReadAll
File.Write text
End If
File.Close
FileOver.Close
FSO.DeleteFile(PathOverwrite)
End Sub
Sub CreatePlaylist(folderPath)
Dim fso, folder, file, media
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(folderPath)
For each file in folder.Files
Ext = Array("mp3", "mp4", "mid", "midi", "wav", "wma", "m4a", "flac", "aac", "ogg", "oga", "webm", "weba", "opus", "3gp", "3g2", "amr", "aiff", "aif", "aifc", "mka", "mkv")
For each filetype in Ext
If LCase(fso.GetExtensionName(file.name)) = LCase(filetype) Then
REDIM PRESERVE oSongArray(UBound(oSongArray) + 1)
oSongArray(UBound(oSongArray)) = file.name
Set media = oPlayer.newMedia(file.Path)
oPlaylist.appendItem(media)
end if
Next
Next
End Sub
Sub mp3Selector_OnClick
started = false
oPlayer.controls.pause
isPlaying = false
document.getElementById("PauseImg").src = StatePause
End Sub
Sub mp3Selector_OnChange
document.getElementById("mp3text").innerHTML = Split(document.getElementById("mp3Selector").value, "\")(UBound(Split(document.getElementById("mp3Selector").value, "\")))
oPlaylist.clear
oSongArray = Array()
musicTarget = "Song"
If isPressingSkip = true then ToggleSkip()
End Sub
Sub mp3text_OnResize
If hasLoaded = true AND hasChangedScrollbarPadding = false Then
hasScrollbar = Not hasScrollbar
If hasScrollbar = true Then
document.getElementById("mp3text").style.paddingBottom = "2%"
document.getElementById("mp3text").style.paddingTop = "2%"
document.getElementById("mp3text").style.fontSize = "16px"
hasChangedScrollbarPadding = true
End If
If hasScrollbar = false Then
document.getElementById("mp3text").style.paddingBottom = "4%"
document.getElementById("mp3text").style.paddingTop = "4%"
document.getElementById("mp3text").style.fontSize = "20px"
hasChangedScrollbarPadding = true
End If
Else
hasChangedScrollbarPadding = false
End If
hasLoaded = true
End Sub
Sub mp3folderselector_OnClick
started = false
oPlayer.controls.pause
isPlaying = false
document.getElementById("PauseImg").src = StatePause
Dim folder : Set folder = Shell.BrowseForFolder(0, "Choose a folder", &H4410, 0)
If folder.self.path <> "" Then
playlistName = folder
musicTarget = "Playlist"
oPlaylist.clear
oSongArray = Array()
document.getElementById("mp3text").innerHTML = folder
document.getElementById("mp3folderselector").value = folder.self.path
End If
End Sub
' Called each time a key is pressed
Sub document_OnKeyDown
If Window.event.keyCode = Key_close Then Window.close()
If Window.event.keyCode = Key_pause Then TogglePause()
If Window.event.keyCode = Key_loop Then If started = true Then ToggleLoop()
If Window.event.keyCode = Key_minus Then If started = true Then MinusButton_OnClick()
If Window.event.keyCode = Key_plus Then If started = true Then PlusButton_OnClick()
If Window.event.keyCode = Key_up Then If started = true Then VolumeUpButton_OnClick()
If Window.event.keyCode = Key_down Then If started = true Then VolumeDownButton_OnClick()
If Window.event.keyCode = Key_skip Then If isPressingSkip = false AND musicTarget = "Playlist" Then ToggleSkip()
End Sub
Sub document_OnKeyUp
If Window.event.keyCode = Key_skip Then If musicTarget = "Playlist" Then ToggleSkip()
End Sub
Sub TogglePause
If isPlaying = false Then If pressedSpace = false Then Play()
If isPlaying = true Then If pressedSpace = false Then Pause()
pressedSpace = false
End Sub
Sub PauseButton_OnClick
On Error Resume Next
If document.getElementById("mp3Selector").value <> "" AND musicTarget = "Song" Then
TogglePause()
ElseIf document.getElementById("mp3folderselector").value <> "" AND musicTarget = "Playlist" Then
TogglePause()
End If
End Sub
Sub Play
If started = false Then
StartUp()
End If
document.getElementById("PauseImg").src = StatePlay
oPlayer.controls.play
isPlaying = true
pressedSpace = true
End Sub
Sub Pause
document.getElementById("PauseImg").src = StatePause
oPlayer.controls.pause
isPlaying = false
pressedSpace = true
End Sub
Sub RebindButton_OnClick
Dim arr : arr = Window.showModalDialog(".\Data\hta\Rebind.hta", "", "dialogHeight: 275px; dialogWidth: 200px;")
If Not arr(0) = "" Then Key_close = arr(0)
If Not arr(1) = "" Then Key_pause = arr(1)
If Not arr(2) = "" Then Key_loop = arr(2)
If Not arr(3) = "" Then Key_minus = arr(3)
If Not arr(4) = "" Then Key_plus = arr(4)
If Not arr(5) = "" Then Key_up = arr(5)
If Not arr(6) = "" Then Key_down = arr(6)
If Not arr(7) = "" Then Key_skip = arr(7)
End Sub
Sub MinusButton_OnClick
If isPressingSkip = true Then
oPlayer.controls.previous
Else
oPlayer.controls.currentPosition = oPlayer.controls.currentPosition - 5
End If
End Sub
Sub PlusButton_OnClick
If isPressingSkip = true Then
oPlayer.controls.next
Else
oPlayer.controls.currentPosition = oPlayer.controls.currentPosition + 5
End If
End Sub
Sub VolumeDownButton_OnClick
If oPlayer.settings.volume < 6 Then
document.getElementById("DownImg").src = StateMinVolume
Else
document.getElementById("UpImg").src = StatePlusVolume
End If
oPlayer.settings.volume = oPlayer.settings.volume - 5
startVolume = startVolume - 5
End Sub
Sub VolumeUpButton_OnClick
If oPlayer.settings.volume > 94 Then
document.getElementById("UpImg").src = StateMaxVolume
Else
document.getElementById("DownImg").src = StateMinusVolume
End If
oPlayer.settings.volume = oPlayer.settings.volume + 5
startVolume = startVolume + 5
End Sub
Sub LoopButton_OnClick
ToggleLoop()
End Sub
Sub ToggleLoop
If isLooping = true Then If pressedR = false Then setLoop(False)
If isLooping = false Then If pressedR = false Then setLoop(True)
pressedR = false
End Sub
Sub setLoop(Bool)
oPlayer.settings.setMode "loop", Bool
pressedR = true
If isLooping = true Then document.getElementById("LoopImg").src = StateNoLoop
If isLooping = false Then document.getElementById("LoopImg").src = StateLoop
isLooping = Bool
End Sub
Sub ToggleSkip
isPressingSkip = NOT isPressingSkip
If isPressingSkip = true Then
document.getElementById("-TimeIcon").src = StateMinusSkip
document.getElementById("+TimeIcon").src = StatePlusSkip
End If
If isPressingSkip = false Then
document.getElementById("-TimeIcon").src = StateMinusNoSkip
document.getElementById("+TimeIcon").src = StatePlusNoSkip
End If
End Sub
</script>
<body onselectstart="return false" >
<!-- First Layer -->
<div class="FirstLayer">
<button type="button" id="RebindButton" name="RebindButton" onclick="focus(Window)" tabindex="-1"></button>
</div>
<!-- Second Layer -->
<div class="SecondLayer">
<span id="mp3text" class="mp3text">Choose a song</span>
<label id="mp3wrapper" class="mp3wrapper">
<img id="SongIcon" src=".\Data/png/SongIcon.png" /></button>
<input type="file" class="mp3selector" id="mp3Selector" name="mp3Selector" value="" onclick="focus(Window)" tabindex="-1">
</label>
<a id="mp3folderselector" class="mp3folderselector" value="">
<img id="PlaylistIcon" src=".\Data/png/PlaylistIcon.png" /></button>
</a>
</div>
<!-- Third Layer -->
<div class="ThirdLayer">
<a type="button" id="MinusButton" style="margin-left: 8px" name="MinusButton" onclick="focus(Window)" tabindex="-1">
<img id="-TimeIcon" src=".\Data/png/-TimeIcon.png" onmousedown="return false" /></a>
<a type="button" id="PauseButton" name="PauseButton" onclick="focus(Window)" tabindex="-1">
<img id="PauseImg" src=".\Data/png/PlayIcon.png" onmousedown="return false" /></a>
<a type="button" id="PlusButton" style="margin-right: 45px;" name="PlusButton" onclick="focus(Window)" tabindex="-1">
<img id="+TimeIcon" src=".\Data/png/+TimeIcon.png" onmousedown="return false" /></a>
<a type="button" id="VolumeDownButton" name="VolumeDownButton" onclick="focus(Window)" tabindex="-1">
<img id="DownImg" src=".\Data/png/-VolumeIcon.png" onmousedown="return false" /></a>
<a type="button" id="VolumeUpButton" style="margin-right: 45px;" name="VolumeUpButton" onclick="focus(Window)" tabindex="-1">
<img id="UpImg" src=".\Data/png/+VolumeIcon.png" onmousedown="return false" /></a>
<a type="button" id="LoopButton" name="LoopButton" onclick="focus(Window)" tabindex="-1">
<img id="LoopImg" src=".\Data/png/NoLoopIcon.png" onmousedown="return false" /></a>
</div>
</body>