-
Notifications
You must be signed in to change notification settings - Fork 29
/
AhkPlayer.ahk
1570 lines (1448 loc) · 36.8 KB
/
AhkPlayer.ahk
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
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
下一首:^+F5
上一首: ^+F3
暂停:^+P
加入列表:!F10
显示隐藏歌词:!F8
手气不错:!F9
跳转到指定时间:!F3
编辑歌词:!F5
显示隐藏界面:!F7
移动歌词位置:!F6
退出:^+E
*/
#Persistent
#NoTrayIcon
#SingleInstance force
SetBatchLines, 10ms
DetectHiddenWindows On
SetTitleMatchMode 2
#MaxThreads,255
FileEncoding,CP1200
CoordMode, ToolTip
SingleCycle := false
run_iniFile = %A_ScriptDir%\settings\setting.ini
IniRead, AhkMediaLib, %run_iniFile%, AhkPlayer, AhkMediaLib
IniRead, TTPlayer, %run_iniFile%, AudioPlayer, TTPlayer
IniRead, AutoUpdateMediaLib, %run_iniFile%, AhkPlayer, AutoUpdateMediaLib
IniRead, Lrcfontcolor, %run_iniFile%, AhkPlayer, Lrcfontcolor
IniRead, LrcPath, %run_iniFile%, AhkPlayer, LrcPath
IniRead, LrcPath_Win10, %run_iniFile%, AhkPlayer, LrcPath_Win10
IniRead, LrcPath_2, %run_iniFile%, 路径设置, LrcPath
IniRead, followmouse, %run_iniFile%, AhkPlayer, followmouse
IniRead, PlayListdefalut, %run_iniFile%, AhkPlayer, PlayListdefalut
IniRead, PlayRandom, %run_iniFile%, AhkPlayer, PlayRandom
IniRead, huifushangci, %run_iniFile%, AhkPlayer, huifushangci
IniRead, notepad2, %run_iniFile%, otherProgram, notepad2
lrceditor:=notepad2?notepad2:notepad.exe
global DB := new SQLiteDB
global DBPATH:= A_ScriptDir . "\Settings\AhkPlayer\musiclib.db"
if (!FileExist(DBPATH))
isnewdb := 1
else
isnewdb := 0
if (!DB.OpenDB(DBPATH))
MsgBox, 16, SQLite错误, % "消息:`t" . DB.ErrorMsg . "`n代码:`t" . DB.ErrorCode
if (isnewdb == 1)
migrateHistory()
hidelrc=0
PlaylistIndex=1
ErrCounter:=0
LrcPath:=(SubStr(A_OSVersion, 1, 2)=10)?LrcPath_Win10:LrcPath
LrcPath:=FileExist(LrcPath)?LrcPath:(FileExist(LrcPath_2)?LrcPath_2:"")
AhkMediaLibFile = %A_ScriptDir%\settings\AhkPlayer\mp3s.txt
AhkMediaListFile = %A_ScriptDir%\settings\AhkPlayer\playlist.txt
historyFile = %A_ScriptDir%\Settings\AhkPlayer\history.txt
If (PlayListdefalut="t") || A_Args.Length()>0
{
NowPlayFile := AhkMediaListFile
if A_Args.Length()>0
{
IniWrite, % A_Args[A_Args.Length()], %run_iniFile%, AhkPlayer, Mp3Playing
for n, param in A_Args
{
SplitPath, param,,,ext
If ext in mp3,wma,wmv,wav,mpg,mid,mp4,m4a ;这是我目前已知的能用soundplay播放的格式
Fileappend,%param%`n, %AhkMediaListFile%
}
}
}
else
NowPlayFile := AhkMediaLibFile
Gui, 2: +LastFound +alwaysontop -Caption +Owner -SysMenu
Gui, 2:Margin, 0
Gui, 2:Color, FF0F0F
Gui, 2:Font, s24,msyh ;Gui, 2:Font, s24 bold
Gui, 2:add, Text, w1000 r1.9 c%Lrcfontcolor% vlrc,
posy:=A_ScreenHeight-130
WinSet, TransColor, FF0F0F
WinSet, ExStyle, +0x20
Gui, 2:Show, Hide x150 y%posy%
Menu, FileMenu, Add, 添加文件(&F), MenuFileAdd
Menu, FileMenu, Add, 添加文件夹(&D), MenuFolderAdd
Menu, FileMenu, Add, 保存列表(&S), saveplaylist
Menu, FileMenu, Add, 退出(&X), Exit
Menu, EditMenu, Add, 播放所选(单选)(&O), MenuOpen
Menu, EditMenu, Add, 从列表中删除(&R), MenuRemove
Menu, EditMenu, Add, 清空列表(&C), MenuClear
Menu, EditMenu, Add, 打开文件位置(单选)(&C), MenuOpenFilePath
Menu, PlayBack, Add, 暂停/播放(&P), MyPause
Menu, PlayBack, Add, 停止(&S), Stop
Menu, PlayBack, Add, 跳转到(&J), Jump
Menu, PlayBack, Add, 上一首(&V), Prev
Menu, PlayBack, Add, 下一首(&N), Next
Menu, PlayBack, Add
Menu, PlayBack, Add, 顺序播放(&D), CheckPlayorder
Menu, PlayBack, Add, 随机播放(&R), CheckPlayorder
Menu, PlayBack, Add, 单曲循环(&E), CheckPlayorder
Menu, PlayBack, Add
Menu, PlayBack, Add, 下一首跟随鼠标(&F), PTLF
Menu, PlayBack, Add, 播放列表(&L), PTList
Menu, PlayBack, Add, 播放媒体库(&M), PTLib
Menu, Lib, Add, 编辑歌词(&E), EditLrc
Menu, Lib, Add, 编辑配置文件(&O), EditOption
Menu, Lib, Add
Menu, Lib, Add, 打开歌词库(&L), OpenLrc
Menu, Lib, Add, 打开媒体库(&M), OpenLib
Menu, Lib, Add, 打开配置文件夹(&F), OpenOptionFolder
Menu, Lib, Add
Menu, Lib, Add, 启动恢复上次播放(&H),HuiFuShangCiPlay
Menu, Lib, Add, 更新媒体库(&U),UpdateMediaLib
Menu, Lib, Add, 启动自动更新媒体库(&A),AutoUpdateMediaLib
Menu, Help, Add, 关于(&A), About
If (PlayRandom="t")
Menu,PlayBack,Check,随机播放(&R)
else
Menu,PlayBack,Check,顺序播放(&D)
If (followmouse="t")
Menu,PlayBack,Check,下一首跟随鼠标(&F)
If (PlayListdefalut="t")
{
Menu,PlayBack,Check,播放列表(&L)
Menu,PlayBack,Disable,播放列表(&L)
}
Else
{
Menu, PlayBack, Check,播放媒体库(&M)
Menu,PlayBack,Disable,播放媒体库(&M)
}
if (AutoUpdateMediaLib="t")
Menu, Lib, Check,启动自动更新媒体库(&A)
if (huifushangci = "t")
Menu, Lib, Check,启动恢复上次播放(&H)
Menu, MyMenuBar, Add, 文件(&F), :FileMenu
Menu, MyMenuBar, Add, 编辑(&E), :EditMenu
Menu, MyMenuBar, Add, 控制(&P), :PlayBack
Menu, MyMenuBar, Add, 选项(&O), :Lib
Menu, MyMenuBar, Add, 帮助(&H), :Help
OnExit ExitSub
Gosub,GuiShow
SetTimer,CheckStatus,250
SetTimer,Updatevolume,2000
if (AutoUpdateMediaLib="t")
Gosub, UpdateMediaLib
Else
{
sleep,1000
IfNotExist,%AhkMediaLibFile%
Gosub, UpdateMediaLib
}
if (huifushangci = "t") || A_Args.Length()>0
Gosub,HuifuPlay
else
Gosub, StarPlay
Return
HuiFuShangCiPlay:
IniRead, huifushangci, %run_iniFile%, AhkPlayer,huifushangci
If (huifushangci ="t")
{
Menu,Lib,unCheck,启动恢复上次播放(&H)
IniWrite,f, %run_iniFile%, AhkPlayer, huifushangci
}
Else
{
Menu,Lib,Check,启动恢复上次播放(&H)
IniWrite,t, %run_iniFile%, AhkPlayer, huifushangci
}
Return
AutoUpdateMediaLib:
IniRead, AutoUpdateMediaLib, %run_iniFile%, AhkPlayer,AutoUpdateMediaLib
If (AutoUpdateMediaLib ="t")
{
Menu,Lib,unCheck,启动自动更新媒体库(&A)
IniWrite,f, %run_iniFile%, AhkPlayer, AutoUpdateMediaLib
}
Else
{
Menu,Lib,Check,启动自动更新媒体库(&A)
IniWrite,t, %run_iniFile%, AhkPlayer, AutoUpdateMediaLib
}
Return
UpdateMediaLib:
Count = 0
Tmp_Val := ""
filelistarray := {}
FileDelete, %AhkMediaLibFile%
Loop, %AhkMediaLib%\*.*, 0,1
{
mp3_loop := A_loopfilename
Splitpath, mp3_loop,,,Extension
If Extension in mp3,wma,wmv,wav,mpg,mp4,m4a
{
Tmp_Val .= a_loopfilefullpath "`n"
filelistarray[a_loopfilefullpath]:=1
Count++
}
else
Continue
}
FileAppend, % Tmp_Val, %AhkMediaLibFile%
updateMlib()
Tmp_Val := ""
Count -= 1
IniWrite, %Count%, %run_iniFile%, AhkPlayer, Count
CF_ToolTip("更新媒体库完毕! ",2500)
if (PlayListdefalut="f")
gosub PTLib
Return
HuifuPlay:
IniRead, Mp3, %run_iniFile%, AhkPlayer, Mp3Playing
IniRead, PlaylistIndex, %run_iniFile%, AhkPlayer, PlaylistIndex, 0
if A_Args.Length()>0
LV_Modify(LV_GetCount(),"+Select +Focus +Vis")
else
LV_Modify(PlaylistIndex,"+Select +Focus +Vis")
; 打开文件
goto, Gplay
Return
StarPlay:
If hSound
{
MCI_Stop(hSound)
MCI_Close(hSound)
}
if SingleCycle
goto Gplay
Count :=TF_CountLines(NowPlayFile)
;IniRead, PlayRandom, %run_iniFile%, AhkPlayer, PlayRandom
;IniRead, followmouse, %run_iniFile%, AhkPlayer, followmouse
;IniRead, PlayListdefalut, %run_iniFile%, AhkPlayer, PlayListdefalut
if (PlayRandom = "t") ; 随机播放
{
if (followmouse="t") ; 跟随鼠标
{
if (PlaylistIndex != LV_GetNext(Row))
{
PlaylistIndex:=LV_GetNext(Row)
}
else ; 鼠标所在行是上一首播放的
{
Random, Rand, 1, %Count%
LV_Modify(0,"-Select")
LV_Modify(Rand,"+Select +Focus +Vis")
PlaylistIndex:=LV_GetNext(Row)
}
}
else ; 不跟随鼠标
{
Random, Rand, 1, %Count%
LV_Modify(0,"-Select")
LV_Modify(Rand,"+Select +Focus +Vis")
PlaylistIndex:=LV_GetNext(Row)
}
LV_GetText(Mp3,PlaylistIndex,4)
}
else ; 顺序播放
{
if (PlaylistIndex>=LV_GetCount())
PlaylistIndex:=1
else if (followmouse="t")
{
if (PlaylistIndex=LV_GetNext(Row))
{
PlayListIndex++
if (PlaylistIndex>LV_GetCount())
PlaylistIndex:=1
}
Else
PlaylistIndex:=LV_GetNext(Row)
}
Else
PlayListIndex++
LV_GetText(Mp3,PlaylistIndex,4)
LV_Modify(0,"-Select")
LV_Modify(PlaylistIndex,"+Select +Focus +Vis")
}
IniWrite, %mp3%, %run_iniFile%, AhkPlayer, Mp3Playing
Iniwrite, %PlaylistIndex%, %run_iniFile%,AhkPlayer, PlaylistIndex
Gplay:
if (mp3!="位置")
{
FileRead, Tmp_Val, %historyFile%
file := FileOpen(historyFile, "w", "UTF-16")
file.Write(mp3 "`r`n" Tmp_Val)
file.close()
Tmp_Val := ""
}
hSound := MCI_Open(Mp3, "myfile")
if !hSound
{
ErrCounter+=1
if (ErrCounter>10)
{
Gosub, MyPause
return
}
}
else
ErrCounter:=0
SetTimer UpdateSlider,off
GUIControl,,Slider,0
GUIControl,Disable,Slider
Gosub, MyPause
len := MCI_Length(hSound)
GUIControl,Enable,Slider
SetTimer,UpdateSlider,100
SetTimer,CheckStatus,250
Gosub, ToolTipMP3
; Gosub命令:程序跳转到ToolTipMP3标签,执行标签下的语句,遇到Return或break返回,
; 才继续执行该行下面的语句即继续执行Gosub, StarPlay Goto命令则不会返回
; 播放下一首歌曲
Gosub, StarPlay
Return
Gplay2:
IniWrite, %mp3%, %run_iniFile%, AhkPlayer, Mp3Playing
if (mp3!="位置")
{
FileRead, Tmp_Val, %historyFile%
file := FileOpen(historyFile, "w", "UTF-16")
file.Write(mp3 "`r`n" Tmp_Val)
file.close()
Tmp_Val := ""
}
if (PlayListdefalut="t") && (PlayRandom = "f")
Iniwrite, %PlaylistIndex%, %run_iniFile%,AhkPlayer, PlaylistIndex
SetTimer UpdateSlider,off
GUIControl,,Slider,0
GUIControl Disable,Slider
If hSound
{
MCI_Stop(hSound)
MCI_Close(hSound)
}
hSound := MCI_Open(Mp3, "myfile")
Gosub, MyPause
GUIControl Enable,Slider
Gosub, sNameTrim
len := MCI_Length(hSound)
MCI_ToHHMMSS2(pos, hh, mm, ss)
MCI_ToHHMMSS2(len, hh, lm, ls)
SetTimer UpdateSlider,100
SetTimer,CheckStatus,250
if (ErrCounter=11)
{
ErrCounter:=0
Gosub, StarPlay
}
Return
CreatContext:
Menu, Context, Add, 播放(单选), PlayLV
Menu, Context, Add, 千千静听打开(单选), TTplayerOpen
Menu, Context, Add, 打开文件位置(单选), OpenfilePath
Menu, Context, Add, 添加到列表, AddList
Menu, Context, Add, 从列表中删除(可多选), Remove
Menu, Context, Add, 清空列表, Remove
Menu, Context, Add, 清除列表中的重复与无效项, RemoveDuplicateInvalid
return
GuiShow:
Gui, Menu, MyMenuBar
pld:=(PlayListdefalut="t")?1:2
Gui, Add,DropDownList, vSelectedplaylist y5 w80 gSelectPlayList Choose%pld%,默认列表|媒体库|历史列表
spo:=(PlayRandom="t")?2:1
Gui, Add,DropDownList, x+5 yp w80 vSelectedPlayorder gSelectPlayorder Choose%spo%,默认|随机|单曲循环
Gui, Add, Edit, x+5 yp+1 w250 vfind
Gui, Add, Button, x+5 yp h20 gfind Default, 查找
Gui, Add, Button, x+5 yp h20 grefreshList, 返回列表
Gui, Add, Button, x+5 yp h20 gFindToList, 追加到列表
Gui, Add,ListView ,xm Grid w600 h400 gListView Count5000 vListView Altsubmit, 序号|曲名|类型|位置|创建时间|上次播放|大小|播放次数
Gui, Add,Slider,xm w600 h25 +Disabled -ToolTip vSlider page1 gSlider AltSubmit
Gui, Add,Picture,xm+150 y+10 vstop gStop,%A_ScriptDir%\pic\AhkPlayer\stop.bmp
Gui, Add,Picture,x+1 yp-1 gprev,%A_ScriptDir%\pic\AhkPlayer\prev.bmp
Gui, Add,Picture,x+1 yp-10 gMyPause vpausepic,%A_ScriptDir%\pic\AhkPlayer\play.bmp
Gui, Add,Picture,x+1 yp+10 gnext,%A_ScriptDir%\pic\AhkPlayer\next.bmp
Gui, Add,Picture, x+10 yp w32 h32 gmute vvol, %A_ScriptDir%\pic\vol.ico
Gui, Add,Slider, x+1 yp+10 w100 h20 vVSlider Range0-100 +ToolTip gSetVolume
Gui, font,cred bold s24,Verdana
Gui, Add, text, x+5 yp-15 vLrcS gLrcShow ,Lrc
Gui, font
Gui, Add, StatusBar, xm yp w600 h30, 未播放文件
if !LrcPath
GuiControl, Disable, LrcS
vol_Master := VA_GetVolume()
Guicontrol,,VSlider,%vol_Master%
SB_SetParts(300,100,220)
SB_SetProgress(0 ,3,"-smooth")
gosub CreatContext
If (PlayListdefalut="t"){
AhkPlayer_Title:="播放列表 - AhkPlayer"
gosub,refreshList
}
else
{
AhkPlayer_Title:="播放媒体库 - AhkPlayer"
if !mLiblistview()
gosub,refreshList
menu, Context, DeleteAll
}
Gui,Show,,%AhkPlayer_Title%
Return
; 停止播放,返回开头
Stop:
SetTimer,CheckStatus,Off
MCI_Stop(hSound)
MCI_Seek(hSound,0)
Menu, PlayBack, Check,停止(&S)
Gui,2:hide
lrcclear()
SetTimer, clock,Off
GUIControl,,Slider,0
gosub,CheckStatus
Return
ToolTipMP3:
if (Exit = true)
Exit
; 例如前一个热键仍在执行时又按了另一个热键,那么当前线程将被中断(暂时地停止)以允许新的线程变成当前的线程
; StarPlay中的ToolTipMP3为当前进程,按下!F9后,当前进程终止进入休眠状态,!F1的ToolTipMP3变为当前的线程
; 当!F9的ToolTipMP3线程运行完毕之后,StarPlay中的ToolTipMP3恢复
; 所以按下!F9播放后,热键的线程在持续运行时,再次按下热键没用,因为上一次的热键还没有结束
Exit = false
Gosub, sNameTrim
len := MCI_Length(hSound)
Loop {
IniRead, ToolMode, %run_iniFile%, AhkPlayer, ToolMode
IniRead, ToolX, %run_iniFile%, AhkPlayer, ToolX
IniRead, ToolY, %run_iniFile%, AhkPlayer, ToolY
Sleep 100
pos := MCI_Position(hSound)
If(pos >= len){
IniWrite, %mp3%, %run_iniFile%, AhkPlayer, LastPlay
if (PlayListdefalut = "f")
{
updatemusicfile(mp3)
}
Break
}
MCI_ToHHMMSS2(pos, hh, mm, ss)
MCI_ToHHMMSS2(len, lhh, lm, ls)
;If (ToolMode = 0)
;tooltip
If (ToolMode = 1){
if lhh=0
ToolTip, %sName%`n%mm%:%ss% / Length %lm%:%ls%, %ToolX%, %ToolY%
else
ToolTip, %sName%`n%hh%:%mm%:%ss% / Length %lhh%:%lm%:%ls%, %ToolX%, %ToolY%
}
Else If (ToolMode = 2)
{
if lhh=0
ToolTip, %sName%`n%mm%:%ss% / Length %lm%:%ls%`n%mp3%, %ToolX%, %ToolY%
else
ToolTip, %sName%`n%hh%:%mm%:%ss% / Length %lhh%:%lm%:%ls%`n%mp3%, %ToolX%, %ToolY%
}
}
Return
PlayfromList:
FileReadLine, Mp3, %AhkMediaLibFile%, %PlayIndex%
If hSound
MCI_Close(hSound)
hSound := MCI_Open(Mp3, "myfile")
MCI_Play(hSound)
if(hidelrc=0)
Gosub, Lrc
Gosub, sNameTrim
len := MCI_Length(hSound)
MCI_ToHHMMSS2(pos, hh, mm, ss)
MCI_ToHHMMSS2(len, hh, lm, ls)
Return
ListReadWrite:
IniRead, Count, %run_iniFile%, AhkPlayer, Count
IniRead, PlayIndex, %run_iniFile%, AhkPlayer, PlayIndex
if (A_ThisHotkey="PgUp")
PlayIndex-=1
if (A_ThisHotkey="PgDn")
PlayIndex+=1
if (PlayIndex=0)
PlayIndex := Count
if (PlayIndex > Count)
PlayIndex = 1
IniWrite, %PlayIndex%, %run_iniFile%, AhkPlayer, PlayIndex
Return
sNameTrim:
StringLen, sLength, mp3
StringGetPos, cTrim, mp3, \, R1
cTrim += 2
fName := (sLength+1) - cTrim
StringMid, sName, mp3, %cTrim%, %fName%
Return
Lrc:
lrcclear()
SetTimer, clock, Off
newname:=""
SplitPath, Mp3,,,ext, name
If FileExist(LrcPath "\" name ".lrc")
{
Menu,Lib,Enable,编辑歌词(&E)
lrcECHO(LrcPath . "\" . name . ".lrc", name)
Return
}
else If FileExist(LrcPath_2 "\" name ".lrc")
{
Menu,Lib,Enable,编辑歌词(&E)
lrcECHO(LrcPath_2 . "\" . name . ".lrc", name)
Return
}
Else
{
newname:=StrReplace(name, " - ", "-",,1)
If FileExist(LrcPath "\" newname ".lrc")
{
Menu,Lib,Enable,编辑歌词(&E)
lrcECHO(LrcPath . "\" . newname . ".lrc", name)
Return
}
else If FileExist(LrcPath_2 "\" newname ".lrc")
{
Menu,Lib,Enable,编辑歌词(&E)
lrcECHO(LrcPath_2 . "\" . newname . ".lrc", name)
Return
}
Else
{
newname:=""
Gui, 2:+LastFound
GuiControl, 2:, lrc,%name%(歌词欠奉)
SetTimer, hidenolrc, -6500
Gui, 2:Show, NoActivate, %name% - AhkPlayer
Menu,Lib,Disable,编辑歌词(&E)
Return
}
}
Return
hidenolrc:
Gui, 2:hide
Return
;上一首
^+F3::
prev:
if (PlayListdefalut="t") && !SingleCycle
{
if (PlaylistIndex>1)
{
PlaylistIndex:=PlaylistIndex-1
LV_GetText(Mp3,PlaylistIndex,4)
LV_Modify(0,"-Select")
LV_Modify(PlaylistIndex,"+Select +Focus +Vis")
gosub, Gplay2
}
}
Else
MCI_Seek(hSound, MCI_Length(hSound))
Return
; 暂停
^+P::
MyPause:
Status := MCI_Status(hSound)
; 状态 playing、stopped、stopped
If(Status = "stopped" OR Status = "Paused")
{
If Status = stopped
{
MCI_Play(hSound)
Menu, PlayBack, UnCheck,停止(&S)
Menu, PlayBack, UnCheck,暂停/播放(&P)
if(hidelrc=0)
Gosub, Lrc
SetTimer,CheckStatus,on
}
Else if Status = Paused
{
MCI_Resume(hSound)
if(hidelrc=0)
{
lrcPause(0)
Gui,2:show
}
Menu, PlayBack, ToggleCheck,暂停/播放(&P)
}
GuiControl,,pausepic, %A_ScriptDir%\pic\AhkPlayer\play.bmp
SetTimer UpdateSlider,on
}
Else
{
Pausetime:=A_TickCount
MCI_Pause(hSound)
if(hidelrc=0)
{
lrcPause(1)
hidelrc=2
gosub lrcshow
}
Menu, PlayBack, ToggleCheck,暂停/播放(&P)
GuiControl,,pausepic,%A_ScriptDir%\pic\AhkPlayer\pause.bmp
SetTimer UpdateSlider,off
}
Return
; 下一首
^+F5::
Next:
MCI_Seek(hSound, MCI_Length(hSound))
if (hidelrc=0)
Gosub, Lrc
Return
; 退出程序
^+E::
Exit:
ExitSub:
If hSound
{
MCI_Stop(hSound)
MCI_Close(hSound)
}
ExitApp
Return
; 播放包含关键字的歌曲
!F9::
;Exit = true
PlayMusic:
InputBox,userInput,查找,输入要查找的歌曲
IfEqual,userInput,, Return
Found = No
Loop, read, %AhkMediaLibFile%
{
mp3 = %A_LoopReadline%
Loop, Parse, UserInput, %a_Space%
{
IfInString, mp3, %A_LoopField%
SetEnv, Found, Yes
}
IfEqual, Found, Yes
{
Gosub, Gplay2
Break
}
}
Return
!F3::
Jump:
InputBox, Seek,跳转,输入要跳转到的时间,歌词不支持跳转`n例子:要跳转到2:20输入220
IfEqual,Seek,, Return
StringLen, Length, Seek
If Length = 4
{
StringLeft, MinS, Seek, 2
StringRight, SecS, Seek, 2
}
Else If Length = 3
{
StringLeft, MinS, Seek, 1
StringRight, SecS, Seek, 2
}
Else If Length = 2
StringRight, SecS, Seek, 2
Else If Length = 1
StringRight, SecS, Seek, 1
lrcpos := SecS * 1000
lrcpos += (MinS * 60) * 1000
MCI_Seek(hSound, lrcpos)
IfWinExist, %name% - AhkPlayer
{
SetTimer, clock, off
gosub,LRC
}
Return
!F5::
if (newname="")
{
IfExist,%LrcPath%\%name%.lrc
run,%lrceditor% %LrcPath%\%name%.lrc
IfExist,%LrcPath_2%\%name%.lrc
run,%lrceditor% %LrcPath_2%\%name%.lrc
return
}
else
{
IfExist,%LrcPath%\%newname%.lrc
run,%lrceditor% %LrcPath%\%newname%.lrc
IfExist,%LrcPath_2%\%newname%.lrc
run,%lrceditor% %LrcPath_2%\%newname%.lrc
return
}
CF_ToolTip("歌词文件不存在!",3000)
Return
!F6::
if caption
{
Gui, 2:+LastFound -Caption
WinSet, ExStyle, +0x20 ; 点击穿透
caption=0
}
Else
{
caption=1
Gui, 2:+Caption ;经测试,的确需要这样写才能够在第一次使用的时候生效
Gui, 2:+LastFound -Caption
WinSet, ExStyle, -0x20
Gui, 2:+Caption
}
Return
!F8::
LrcShow:
if (hidelrc=1)
{
Gui, Font,cred bold s24,Verdana
GuiControl,font,LrcS
hidelrc=0
;IniWrite, 1, %A_ScriptDir%\tmp\setting.ini, AhkPlayer, ToolMode
Gui,2:show
}
Else if (hidelrc=0)
{
Gui, Font, cgreen bold s24,Verdana
GuiControl,font,LrcS
hidelrc=1
Gui,2:Hide
}
Else if (hidelrc=2)
{
hidelrc=0
Gui,2:Hide
}
Return
!F7::
If hide=1
{
SetTimer,Updatevolume,2000
Sleep,150
gui,Show,,%AhkPlayer_Title%
hide=0
}
Else
{
IfWinNotActive,%AhkPlayer_Title%
WinActivate,%AhkPlayer_Title%
else
{
gui,Show,hide,%AhkPlayer_Title%
SetTimer,Updatevolume,off
hide=1
}
}
Return
; 将正在播放的文件加入到播放列表
!F10::
FileRead, NoDoubles, %AhkMediaListFile%
IfNotInString, NoDoubles, %mp3%
Fileappend, %mp3%`n, %AhkMediaListFile%
else
MsgBox,,添加失败,该文件已在播放列表中!
Return
PgUp::
Gosub, ListReadWrite
Gosub, PlayfromList
Return
PgDn::
Pagedown:
Gosub, ListReadWrite
Gosub, PlayfromList
Return
mute:
Send {Volume_Mute}
Gosub,Updatevolume
;GUIControl Focus,Stop
Return
SetVolume:
VA_SetVolume(VSlider)
Return
; 菜单添加文件到列表
MenuFileAdd:
Gui,Submit, NoHide
FileSelectFile, File, M,, 添加文件, 音频文件 (*.mp3; *.wma; *.wav; *.mid; *.mp4; *.m4a)
if !File
return
LV_Modify(0, "-Select")
StringSplit, File, File, `n
Loop, % File0-1
{
xuhao++
NextIndex := A_Index+1
w:=File%NextIndex%
mp3_loop = %File1%\%w%
SplitPath, mp3_loop,,,ext, name
If ext in mp3,wma,wmv,wav,mpg,mid,mp4,m4a ;这是我目前已知的能用soundplay播放的格式
{
SetFormat, float ,03
LV_Add("Focus Select",xuhao+0.0,name,ext, mp3_loop)
Fileappend,%mp3_loop%`n, %AhkMediaListFile%
}
}
LV_ModifyCol()
LV_Modify(xuhao,"+Vis")
Return
; 菜单添加文件夹到列表
MenuFolderAdd:
Gui,Submit, NoHide
FileSelectFolder, Folder,,, 选择音频文件所在文件夹
If !Folder
return
LV_Modify(0, "-Select")
Loop, %Folder%\*.*,0,1
{
xuhao++
SplitPath, A_LoopFileFullPath,,, ext, name
If ext in mp3,wma,wav,mid,mp4,mpg,m4a
{
SetFormat, float ,03
LV_Add("Focus Select",xuhao+0.0, name,ext, A_LoopFileFullPath)
Fileappend,%A_LoopFileFullPath%`n, %AhkMediaListFile%
}
}
LV_ModifyCol()
LV_Modify(xuhao,"+Vis")
return
; 拖拽文件到窗口
GuiDropFiles:
Gui, Submit, NoHide
LV_Modify(0, "-Select")
SetFormat,float ,3.0
Loop, Parse, A_GuiEvent, `n
{
xuhao++
SplitPath, A_LoopField,,,ext, name
If ext in mp3,wma,wmv,wav,mpg,mid,mp4,m4a ;这是我目前已知的能用soundplay播放的格式
{
SetFormat, float ,03
LV_Add("Focus Select",xuhao+0.0, name,ext, A_LoopField)
Fileappend,%A_LoopField%`n, %AhkMediaListFile%
}
}
LV_ModifyCol()
LV_Modify(xuhao,"+Vis")
Return
; 菜单播放所选(单选)
MenuOpen:
LV_GetText(Mp3, LV_GetNext(Row), 4)
PlaylistIndex:=LV_GetNext(Row)
if FileExist(Mp3)
Gosub, Gplay2
Return
; 菜单/右键 打开所选文件位置(单选)
MenuOpenFilePath:
OpenfilePath:
LV_GetText(mp3_loop, LV_GetNext(Row), 4)
If Fileexist(mp3_loop)
File_OpenAndSelect(mp3_loop)
Return
; 菜单从列表中删除(可多选)
MenuRemove:
FileLineCount :=TF_CountLines(AhkMediaListFile)
LVLineCount :=LV_GetCount()
if(FileLineCount - LVLineCount >2)
{
msgbox,错误!不是播放列表,当前菜单不可用。
return
}
else
{
Loop, % LV_GetCount() ;%
Row := LV_GetNext(Row), LV_Delete(Row)
FileDelete, %AhkMediaListFile%
Loop, % LV_GetCount()
{
LV_GetText(mp3_loop, A_Index, 4)
Fileappend,%mp3_loop%`n, %AhkMediaListFile%
}
gosub,refreshList
}
Return
MenuClear:
MsgBox,4,清空列表,确实要将列表清空吗?移动列表文件到备份Backups文件夹(只保留一个备份)。
IfMsgBox Yes
{
LV_Delete()
FileGetSize, playlistfilesize, %AhkMediaListFile%
if (playlistfilesize <> 0)
FileDelete,%A_ScriptDir%\Backups\playlist.txt
FileMove, %AhkMediaListFile%,%A_ScriptDir%\Backups,0
if ErrorLevel
MsgBox,,清空列表失败,列表已经为空或文件不可读写
Fileappend, , %AhkMediaListFile%
}
Return
SelectPlayorder:
Gui, Submit, NoHide
GuiControl, Focus, find
if(SelectedPlayorder="默认")
{
Menu,PlayBack,Check,顺序播放(&D)
Menu,PlayBack,unCheck,随机播放(&R)
Menu,PlayBack,unCheck,单曲循环(&E)
PlayRandom := "f"
SingleCycle := flash
IniWrite,f, %run_iniFile%, AhkPlayer, PlayRandom
return
}
else if(SelectedPlayorder="随机")
{
Menu,PlayBack,Check,随机播放(&R)
Menu,PlayBack,unCheck,顺序播放(&D)
Menu,PlayBack,unCheck,单曲循环(&E)
PlayRandom := "t"
SingleCycle := flash
IniWrite,t, %run_iniFile%, AhkPlayer, PlayRandom
return
}
else if(SelectedPlayorder="单曲循环")
{
SingleCycle:=true
Menu,PlayBack,Check,单曲循环(&E)
}
return
SelectPlayList:
Gui, Submit, NoHide
GuiControl, Focus, find
if(Selectedplaylist="默认列表")
{
gosub PTList
return
}
else if(Selectedplaylist="媒体库")
{
gosub PTLib
return
}
else ; 历史列表
{
LV_Delete()
file := FileOpen(historyFile, "r", "UTF-16")