-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCore.pas
2877 lines (2684 loc) · 109 KB
/
Core.pas
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
{ MPUI-hcb, an MPlayer frontend for Windows
Copyright (C) 2006-2013 Huang Chen Bin <[email protected]>
based on work by Martin J. Fiedler <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
}
unit Core;
interface
uses Windows, TntWindows, SysUtils, TntSysUtils, TntSystem, Classes, Forms, Menus, TntMenus,
Controls, Graphics, Dialogs, MultiMon, ShlObj, TntClasses, INIFiles;
const ABOVE_NORMAL_PRIORITY_CLASS: Cardinal = $00008000;
const PauseCMD: array[0..1] of WideString = ('pause', 'frame_step');
const PauseInfo: array[0..1] of WideString = ('= PAUSE =', '= 暂停 =');
const CacheFill: array[0..4] of WideString = ('Cache fill:', '缓存填充:', '缓冲填充:', '緩存填充:', '緩沖填充:');
const GenIndex: array[0..2] of WideString = ('Generating Index:', '正在生成索引:', '正在生成索引:');
const defaultHeight = 340; RFileMax = 50; stopTimeout = 1000; Dsubpos = 96;
const szdllCount = 2; Fscale = 4.2;
const sddll = 'SubDownloader.dll';
const szdll: array[0..szdllCount] of WideString = ('7zxa.dll', '7za.dll', '7z.dll');
const SubTypeCount = 15;
SubType: array[0..SubTypeCount] of WideString = (
'.lrc', '.utf', '.utf8', '.utf-8', '.srt', '.smi', '.rt', '.txt', '.ssa', '.aqt', '.jss',
'.js', '.ass', '.mpsub', '.idx', '.sub'
);
const ZipTypeCount = 19;
const MediaType: array[0..229] of WideString = ('.7z', '.rar', '.zip', '.001', '.arj', '.bz2', '.z', '.lzh',
'.cab', '.lzma', '.xar', '.hfs', '.dmg', '.wim', '.split', '.rpm', '.deb', '.cpio','.tar', '.gz',
'.aac', '.ac3', '.acc', '.act', '.aif', '.aifc', '.aiff', '.alac', '.amf', '.amr', '.amv', '.ape',
'.as', '.asf', '.asx',
'.a52', '.ape', '.apl', '.au', '.avi', '.avs', '.bik', '.bin', '.cda', '.cmf', '.cmn', '.cpk', '.csf',
'.d2v', '.dat', '.drc', '.dsm', '.dsv', '.dsa', '.dss', '.dts', '.dtswav',
'.dv', '.dvd', '.dvr-ms', '.divx', '.evo', '.f4v', '.far', '.fla', '.flac', '.flc', '.fli', '.flic', '.flm',
'.flv', '.grf', '.hdmov', '.hlv',
'.img', '.iso', '.ivf', '.ivm', '.it', '.itz', '.jsv', '.kar', '.m1a', '.m2a', '.m2p', '.m2t', '.m2ts',
'.m1v', '.m2v', '.m3u', '.m3u8', '.m4a', '.m4b', '.m4p', '.m4v', '.mac', '.mdz', '.mid',
'.midi', '.miz', '.mjf', '.mka', '.mkv', '.mod', '.mov', '.mp1', '.mp2', '.mp2v',
'.mp3', '.mp3pro', '.mp4', '.mp4v', '.mp5', '.mpa', '.mpc', '.mpcpl', '.mpe',
'.mpeg', '.mpeg1', '.mpeg2', '.mpeg4', '.mpg', '.mpga', '.mp+', '.mpp',
'.mtm', '.mpv', '.mpv2', '.mpv4', '.mqv', '.mts', '.nrg', '.nsa', '.nst', '.nsv', '.nuv', '.ofr', '.ofs', '.oga', '.ogg',
'.ogm', '.ogv', '.ogx', '.okt', '.pls', '.pm2', '.pmp',
'.pmp2', '.pss', '.ptm', '.pva', '.qt', '.ra', '.ram', '.rat', '.ratdvd', '.rm', '.rmi', '.rmj',
'.rmm', '.rmp', '.rms', '.rmvb', '.rmx', '.rnx', '.roq', '.rp', '.rpm', '.rsc', '.rsm', '.rt', '.rv', '.realpix',
'.s3m', '.s3z', '.scm', '.sdp', '.smil', '.smk', '.smpl', '.smv', '.snd', '.stm', '.stz', '.swa', '.swf', '.tim', '.tod', '.tp', '.tpr',
'.tps', '.ts', '.tta', '.ttpl', '.ult', '.umx', '.vcd', '.vfw', '.vg2', '.vid', '.vivo', '.vob', '.voc', '.vp3', '.vp4', '.vp5',
'.vp6', '.vp7', '.vqf', '.wav', '.wax', '.webm', '.wm', '.wma', '.wmp', '.wmv', '.wmx',
'.wpl', '.wv', '.wvx', '.xm', '.xmz', '.xspf',
'.261', '.264', '.3g2', '.3gp', '.3gpp', '.3gp2', '.669'
);
const PlaylistType: array[0..10] of WideString = (
'.m3u', '.asx', '.wpl', '.pls', '.ttpl', '.rmp', '.xspf',
'.smpl', '.m3u8', '.mpcpl', '.wmx'
);
const VideoDemuxer: array[0..5] of WideString = (
'avinini', 'avini', 'avi', 'mpegts', 'lavf', 'lavfpref'
);
const AudioDemuxer: array[0..12] of WideString = (
'mkv', 'mpegts', 'mpegps', 'mpegpes', 'mpeges',
'mpeg4es', 'h264es', 'lavf', 'lavfpref', 'avinini', 'avini', 'avi', 'pmp'
);
const DefaultFass = '0aac,1ac3,1acc,1act,1aif,1aifc,1aiff,0amf,1amr,1amv,0ape,0as,1asf,1asx,'
+ '0a52,0apl,1au,1avi,0avs,1bik,0bin,0cda,0cmf,0cmn,0cpk,0cue,1d2v,0dat,0drc,'
+ '1dsm,1dsv,1dsa,1dss,1dts,0dtswav,0dv,0dvr-ms,0divx,1evo,0far,0fla,0flac,1flc,'
+ '1fli,1flic,0flm,1flv,0grf,0hdmov,0img,0iso,1ivf,0it,0itz,0jsv,0kar,0m1a,0m2a,'
+ '1m2p,1m2ts,1m1v,1m2v,1m3u,1m3u8,1m4a,1m4b,1m4p,1m4v,0mac,0mdz,0miz,'
+ '0mjf,1mka,1mkv,1mod,1mov,0mp1,1mp2,0mp2v,1mp3,0mp3pro,1mp4,0mp5,0mpa,0mpc,1mpcpl,'
+ '1mpe,1mpeg,1mpg,1mpga,0mp+,0mpp,0mtm,0mpv,0mpv2,0mqv,1mts,0nrg,0nsa,0nst,0nsv,0nuv,'
+ '0ogg,0ogm,0okt,0pls,1pmp,1pmp2,1pss,0ptm,1pva,1qt,1ra,1ram,1ratdvd,1rm,0rmi,0rmj,'
+ '0rmm,0rmp,0rms,1rmvb,0rmx,0rnx,0roq,0rp,1rpm,0rt,0rv,1realpix,0s3m,0s3z,1scm,0sdp,'
+ '1smil,1smk,1smpl,0snd,0stm,0stz,1tp,1tpr,1ts,0tta,0ttpl,0ult,0umx,0vcd,0vfw,1vg2,'
+ '1vid,0vivo,1vob,0voc,0vp3,0vp4,0vp5,1vp6,1vp7,1vqf,0wav,1wax,1wm,1wma,1wmp,1wmv,1wmx,'
+ '0wpl,1wv,1wvx,0xm,0xmz,0xspf,0261,0264,13g2,13gp,13gpp,13gp2,0669';
const DefaultHotKey: array[0..102] of Integer = (
262182, 262184, 262181, 262183, 262331, 262333, 131123, 131264, 131121, 131122,
65601, 65605, 65728, 65619, 65626, 109, 107, 79, 192, 222, 69, 87, 49, 50, 51, 52, 53,
54, 55, 56, 57, 48, 46, 45, 68, 70, 67, 84, 82, 86, 83, 89, 85, 90, 88, 71, 72, 73, 75, 74,
76, 186, 113, 114, 115, 116,117, 9, 13, 262223, 262220, 262231, 262227, 262336, 262225,
262212, 262152, 131187, 65604, 65612, 65618, 37, 39, 38, 40, 33, 34, 36, 35, 8, 189,
187, 77, 78, 66, 81, 80, 188, 190, 65, 112, 120, 121, 122, 123, 219, 221, 220, 191, 32, 118, 119,262209);
const DefaultHKS = '262182,262184,262181,262183,262331,262333,131123,131264,131121,131122,'
+ '65601,65605,65728,65619,65626,109,107,79,192,222,69,87,49,50,51,52,53,'
+ '54,55,56,57,48,46,45,68,70,67,84,82,86,83,89,85,90,88,71,72,73,75,74,'
+ '76,186,113,114,115,116,117,9,13,262223,262220,262231,262227,262336,262225,'
+ '262212,262152,131187,65604,65612,65618,37,39,38,40,33,34,36,35,8,189,'
+ '187,77,78,66,81,80,188,190,65,112,120,121,122,123,219,221,220,191,32,118,119,262209';
type TStatus = (sNone, sOpening, sClosing, sPlaying, sPaused, sStopped, sError);
var Status: TStatus;
HomeDir, SystemDir, TempDir, AppdataDir: WideString;
MediaURL, TmpURL, ArcMovie, Params, AddDirCP,avThread,cl: WideString;
ArcPW, TmpPW, DisplayURL, AudioFile: WideString;
Duration, LyricF, fass, HKS, lastP1, lastFN: string;
substring, Vobfile, ShotDir, LyricDir, LyricURL: WideString;
subfont, osdfont, Ccap, Acap, Tcap, DemuxerName: WideString;
MplayerLocation, WadspL, AsyncV, CacheV: widestring;
MAspect, subcode, VideoOut: string;
FirstOpen, PClear, Fd, Async, Cache, uof, oneM, FilterDrop,AutoDs: boolean;
Wid, Dreset, UpdateSkipBar, Pri, HaveChapters, HaveMsg, skip,bluray,dvd,vcd,cd: boolean;
CT, RP, RS, SP, AutoPlay, ETime, InSubDir, SPDIF, ML, GUI, dlod: boolean;
Shuffle, Loop, OneLoop, Uni, Utf, UseUni,ADls: boolean;
ControlledResize, ni, nobps, Dnav, IsDMenu, SMenu, lavf, UdvdTtime, vsync: boolean;
Flip, Mirror, Yuy2, Eq2, LastEq2, Dda, LastDda, Wadsp, addsFiles, LastAddsfiles: boolean;
WantFullscreen, WantCompact, AutoQuit, IsPause, IsDx, dsEnd,uav: boolean;
VideoID, Ch, CurPlay, LyricS, HaveLyric: integer;
AudioID, MouseMode, SubPos, NoAccess: integer;
SubID, TID, tmpTID, CID, AID, VCDST, CDID: integer;
subcount, Bp, Ep, CurrentLocale: integer;
Lastsubcount: integer;
CurLyric, NextLyric, LyricCount,MaxLenLyric: integer;
VobsubCount, VobFileCount: integer;
CurrentSubCount, OnTop, VobAndInterSubCount, IntersubCount: integer;
IL, IT, EL, ET, EW, EH, InterW, InterH, NW, NH, OldX, OldY, Scale, LastScale: integer;
MFunc, CBHSA, bri, briD, contr, contrD, hu, huD, sat, satD, gam, gamD: integer;
AudioOut, AudioDev, Postproc, Deinterlace, Aspect: integer;
ReIndex, SoftVol, RFScr, dbbuf, nfc, nmsg, Firstrun, Volnorm, Dr: boolean;
Loadsrt, LoadVob, Loadsub, Expand, TotalTime, TTime, ChapterLen, ChaptersLen: integer;
HaveAudio, HaveVideo, LastHaveVideo, ChkAudio, ChkVideo, ChkStartPlay: boolean;
NativeWidth, NativeHeight, MonitorID, MonitorW, MonitorH: integer;
LastPos, Lps, SecondPos, OSDLevel, DefaultOSDLevel, MSecPos: integer;
Volume, MWC, CP, seekLen: integer;
ds, tEnd, procArc, Mute, Ass, Efont, ISub, AutoNext, UpdatePW, sconfig, EndOpenDir: boolean;
DTFormat: string;
FormatSet: TFormatSettings;
ExplicitStop, Rot, DefaultFontIndex: integer;
TextColor, OutColor, LTextColor, LbgColor, LhgColor: Longint;
Speed, FSize, Fol, FB, dy, LyricV, Adelay, Sdelay, balance: real;
CurMonitor: TMonitor;
FontPaths: TTntStringList;
poped: boolean;
PlayMsgAt: Cardinal;
var StreamInfo: record
FileName, FileFormat, PlaybackTime: WideString;
Video: record
Decoder, Codec: WideString;
Bitrate, Width, Height: integer;
FPS, Aspect: real;
end;
Audio: record
Decoder, Codec: Widestring;
Bitrate, Rate, Channels: integer;
end;
ClipInfo: array[0..9] of record
Key, Value: WideString;
end;
end;
MediaInfo: record
FileFormat,VideoCodec,VideoBitRate,VideoWidth,VideoHeight,FrameRate,DisplayAspectRatio,
AudioDecoder,AudioBitRate,AudioSamplingRate, AudioChannel,PlaybackTime:WideString
end;
function CheckMenu(Menu: TMenuItem; ID: integer): integer;
function GetLongPath(const ShortName: WideString): WideString;
function GetLongPathNameA(lpszShortPath, lpszLongPath: PChar; cchBuffer: DWORD): DWORD;
stdcall; external kernel32 name 'GetLongPathNameA';
function GetLongPathNameW(lpszShortPath, lpszLongPath: PWideChar; cchBuffer: DWORD): DWORD;
stdcall; external kernel32 name 'GetLongPathNameW';
procedure AddChain(var Count: integer; var rs: WideString; const s: WideString);
function WideGetEnvironmentVariable(const Name: WideString): WideString;
function WideExpandUNCFileName(const FileName: WideString): WideString;
function WideGetUniversalName(const FileName: WideString): WideString;
function CheckOption(OPTN: WideString): boolean;
function TimeToSeconds(TimeCode: string): integer;
function SecondsToTime(Seconds: integer): string;
function EscapeParam(const Param: widestring): widestring;
function CheckSubfont(Sfont: WideString): WideString;
function CheckInfo(const Map: array of WideString; Value: WideString): integer;
procedure SetLastPos;
procedure Init;
procedure Start;
procedure Stop;
procedure CloseMedia;
procedure Restart;
procedure ForceStop;
function Running: boolean;
function IsLoaded(ArcType: WideString): boolean;
function AddMovies(ArcName, PW: widestring; Add,msg:boolean): integer;
procedure ExtractMovie(ArcName, PW: WideString);
procedure ExtractLyric(ArcName, PW: WideString);
function ExtractSub(ArcName, PW: WideString): WideString;
procedure TerminateMP;
procedure SendCommand(Command: string);
procedure SendVolumeChangeCommand(Vol: integer);
procedure ResetStreamInfo;
function ExpandName(const BasePath, FileName: WideString): WideString;
procedure HandleInputLine(Line: string);
function GetFileName(const fileName: WideString): WideString;
procedure loadLyricSub(path: WideString); overload;
procedure loadLyricSub(folder,filename: WideString); overload;
procedure loadArcLyric(path: WideString); overload;
procedure loadArcLyric(folder,ArcName: WideString); overload;
function loadArcSub(path: WideString):WideString; overload;
function loadArcSub(folder,ArcName: WideString):WideString; overload;
procedure CheckMediaInfo;
implementation
uses Main, config, plist, Info, UnRAR, Equalizer, Locale, Options, SevenZip,
DLyric, OpenDevice, MediaInfoDll;
type TClientWaitThread = class(TThread)
private procedure ClientDone;
protected procedure Execute; override;
public hProcess: Cardinal;
end;
type TProcessor = class(TThread)
private Data: string;
private procedure Process;
protected procedure Execute; override;
public hPipe: Cardinal;
end;
var ClientWaitThread: TClientWaitThread;
Processor: TProcessor;
ClientProcess, ReadPipe, WritePipe: Cardinal;
FirstChance: boolean;
ExitCode: DWORD;
LastLine: string;
LineRepeatCount: integer;
procedure HandleIDLine(ID: string; Content: WideString); forward;
procedure CheckMediaInfo;
var h: Cardinal;
procedure M(z,y:WideString; var o:WideString);
var d: WideString;
begin
MediaInfo_Option (0, 'Inform', PWideChar(z+';%'+y+'%'));
d := MediaInfo_Inform(h, 0);
if d<>'' then o:= d;
end;
begin
if IsMediaInfoLoaded = 0 then MediaInfoDLL_Load;
if IsMediaInfoLoaded <> 0 then begin
FillChar(MediaInfo ,sizeof(MediaInfo),0);
h := MediaInfo_New();
MediaInfo_Open(h,PWideChar(EscapeParam(WideExtractShortPathName(MediaURL))));
M('General','Format',MediaInfo.FileFormat);
M('General','Duration/String3',MediaInfo.PlaybackTime);
M('General','Video_Format_List',MediaInfo.VideoCodec); M('Video','BitRate/String',MediaInfo.VideoBitRate);
M('Video','Width',MediaInfo.VideoWidth); M('Video','Height',MediaInfo.VideoHeight);
M('General','FrameRate/String',MediaInfo.FrameRate); M('Video','DisplayAspectRatio/String',MediaInfo.DisplayAspectRatio);
M('General','Audio_Format_List ',MediaInfo.AudioDecoder); M('Audio','BitRate/String',MediaInfo.AudioBitRate);
M('Audio','SamplingRate/String',MediaInfo.AudioSamplingRate); M('Audio','Channel(s)/String)',MediaInfo.AudioChannel);
MediaInfo_Close(h);
end;
end;
function ExpandName(const BasePath, FileName: WideString): WideString;
begin
Result := FileName;
if (Pos(':', FileName) > 0) or (length(FileName)>515) then exit;
if (length(FileName) > 1) and ((FileName[1] = '/') or (FileName[1] = '\')) then exit;
Result := WideExpandUNCFileName(BasePath + FileName);
end;
function CheckMenu(Menu: TMenuItem; ID: integer): integer;
var a: integer;
begin
for a := Menu.Count - 1 downto 0 do begin
if Menu.Items[a].Tag = ID then begin
Result := a; exit;
end;
end;
Result := -1;
end;
function GetLongPath(const ShortName: WideString): WideString;
var SA: AnsiString;
begin
if Win32PlatformIsUnicode then begin
SetLength(Result, MAX_PATH + 1);
SetLength(Result, GetLongPathNameW(PWideChar(ShortName), PWideChar(Result), MAX_PATH));
end
else begin
SetLength(SA, MAX_PATH + 1);
SetLength(SA, GetLongPathNameA(PChar(AnsiString(ShortName)), PChar(SA), MAX_PATH));
Result := WideString(SA);
end;
end;
function GetFileName(const fileName: WideString): WideString;
begin
Result := WideChangeFileExt(fileName, '');
end;
procedure loadLyricSub(path: WideString);
var t,i: integer; m,n:WideString;
begin
m:=GetFileName(path);
if path<>MediaURL then begin
if (LoadVob=0) and WideFileExists(m + '.idx') and WideFileExists(m + '.sub') then begin //idx
LoadVob := 1; Vobfile := m; end;
for i := 1 to SubTypeCount - 2 do begin //srt,etc
n := m + SubType[i];
if WideFileExists(n) then begin
if (not IsWideStringMappableToAnsi(n)) or (pos(',', n) > 0) then n := WideExtractShortPathName(n);
if pos(n,substring)=0 then begin
Loadsub := 2; Loadsrt := 2;
AddChain(t, substring, EscapeParam(n));
end;
end;
end;
end;
if HaveLyric = 0 then begin
n := m + '.lrc';
if not WideFileExists(n) then begin
n:=WideIncludeTrailingPathDelimiter(ExpandName(HomeDir, LyricDir));
n := n + WideExtractFileName(m) + '.lrc';
end;
if WideFileExists(n) then Lyric.ParseLyric(n);
end;
end;
procedure loadLyricSub(folder, filename: WideString);
begin
loadLyricSub(WideIncludeTrailingBackslash(folder) + filename);
end;
procedure loadArcLyric(path: WideString);
begin
loadArcLyric(WideExtractFileDir(path),WideExtractFileName(path));
end;
procedure loadArcLyric(folder, ArcName: WideString);
var i: integer; s:WideString;
begin
ArcName := WideIncludeTrailingBackslash(folder) + GetFileName(ArcName);
for i := 0 to ZipTypeCount do begin
if WideFileExists(ArcName + MediaType[i]) then begin
if IsLoaded(MediaType[i]) then begin
s:=ArcName + MediaType[i];
if HaveLyric = 0 then ExtractLyric(s, playlist.FindPW(s))
else exit;
end;
end;
end;
end;
function loadArcSub(path: WideString):WideString;
begin
Result:=loadArcSub(WideExtractFileDir(path),WideExtractFileName(path));
end;
function loadArcSub(folder, ArcName: WideString):WideString;
var i: integer; s:WideString;
begin
Result := ''; ArcName := WideIncludeTrailingBackslash(folder) + GetFileName(ArcName);
for i := 0 to ZipTypeCount do begin
if WideFileExists(ArcName + MediaType[i]) then begin
if IsLoaded(MediaType[i]) then begin
s:=ArcName + MediaType[i];
if Result = '' then Result := ExtractSub(s, playlist.FindPW(s))
else exit;
end;
end;
end;
end;
function IsLoaded(ArcType: WideString): boolean;
begin
if ArcType = '.rar' then begin
LoadRarLibrary;
Result := IsRarLoaded <> 0;
if not Result then begin
Load7zLibrary;
Result := Is7zLoaded > 2;
end;
end
else if ArcType = '.zip' then begin
LoadZipLibrary;
Result := IsZipLoaded <> 0;
if not Result then begin
Load7zLibrary;
Result := Is7zLoaded > 2;
end;
end
else begin
Load7zLibrary;
if (ArcType = '.7z') or (ArcType = '.001') then begin
Result := Is7zLoaded <> 0;
if not Result then begin
LoadZipLibrary;
Result := IsZipLoaded <> 0;
end;
end
else Result := Is7zLoaded > 2;
end;
end;
function AddMovies(ArcName, PW: widestring; Add,msg:boolean): integer;
var ArcType:WideString;
begin
Result := -1; ArcType:=Tnt_WideLowerCase(WideExtractFileExt(ArcName));
if ArcType = '.rar' then begin
if IsRarLoaded <> 0 then Result := AddRarMovies(ArcName, PW, Add, msg)
else if Is7zLoaded > 2 then Result := Add7zMovies(ArcName, PW, Add, msg);
end
else if ArcType = '.zip' then begin
if IsZipLoaded <> 0 then Result := AddZipMovies(ArcName, PW, Add, msg)
else if Is7zLoaded > 2 then Result := Add7zMovies(ArcName, PW, Add, msg);
end
else if (ArcType = '.7z') or (ArcType = '.001') then begin
if Is7zLoaded <> 0 then Result := Add7zMovies(ArcName, PW, Add, msg)
else if IsZipLoaded <> 0 then Result := AddZipMovies(ArcName, PW, Add, msg);
end
else if Is7zLoaded > 2 then Result := Add7zMovies(ArcName, PW, Add, msg);
end;
procedure ExtractMovie(ArcName, PW: widestring);
var ArcType:WideString;
begin
ArcType:=Tnt_WideLowerCase(WideExtractFileExt(ArcName));
if ArcType = '.rar' then begin
if IsRarLoaded <> 0 then ExtractRarMovie(ArcName, PW)
else if Is7zLoaded > 2 then Extract7zMovie(ArcName, PW);
end
else if ArcType = '.zip' then begin
if IsZipLoaded <> 0 then ExtractZipMovie(ArcName, PW)
else if Is7zLoaded > 2 then Extract7zMovie(ArcName, PW);
end
else if (ArcType = '.7z') or (ArcType = '.001') then begin
if Is7zLoaded <> 0 then Extract7zMovie(ArcName, PW)
else if IsZipLoaded <> 0 then ExtractZipMovie(ArcName, PW);
end
else if Is7zLoaded > 2 then Extract7zMovie(ArcName, PW);
end;
procedure ExtractLyric(ArcName, PW: WideString);
var ArcType:WideString;
begin
if ArcMovie='' then exit;
ArcType:=Tnt_WideLowerCase(WideExtractFileExt(ArcName));
if ArcType = '.rar' then begin
if IsRarLoaded <> 0 then ExtractRarLyric(ArcName, PW)
else if Is7zLoaded > 2 then Extract7zLyric(ArcName, PW);
end
else if ArcType = '.zip' then begin
if IsZipLoaded <> 0 then ExtractZipLyric(ArcName, PW)
else if Is7zLoaded > 2 then Extract7zLyric(ArcName, PW);
end
else if (ArcType = '.7z') or (ArcType = '.001') then begin
if Is7zLoaded <> 0 then Extract7zLyric(ArcName, PW)
else if IsZipLoaded <> 0 then ExtractZipLyric(ArcName, PW);
end
else if Is7zLoaded > 2 then Extract7zLyric(ArcName, PW);
end;
function ExtractSub(ArcName, PW: WideString): WideString;
var ArcType:WideString;
begin
Result := ''; ArcType:=Tnt_WideLowerCase(WideExtractFileExt(ArcName));
if ArcType = '.rar' then begin
if IsRarLoaded <> 0 then Result := ExtractRarSub(ArcName, PW)
else if Is7zLoaded > 2 then Result := Extract7zSub(ArcName, PW);
end
else if ArcType = '.zip' then begin
if IsZipLoaded <> 0 then Result := ExtractZipSub(ArcName, PW)
else if Is7zLoaded > 2 then Result := Extract7zSub(ArcName, PW);
end
else if (ArcType = '.7z') or (ArcType = '.001') then begin
if Is7zLoaded <> 0 then Result := Extract7zSub(ArcName, PW)
else if IsZipLoaded <> 0 then Result := ExtractZipSub(ArcName, PW);
end
else if Is7zLoaded > 2 then Result := Extract7zSub(ArcName, PW);
end;
function WideGetEnvironmentVariable(const Name: WideString): WideString;
var Len: integer;
begin
Result := '';
if Win32PlatformIsUnicode then begin
Len := GetEnvironmentVariableW(PWChar(Name), nil, 0);
if Len > 0 then begin
SetLength(Result, Len - 1);
GetEnvironmentVariableW(PWChar(Name), PWChar(Result), Len);
end;
end
else Result := WideString(GetEnvironmentVariable(string(Name)));
end;
function WideExpandUNCFileName(const FileName: WideString): WideString;
begin
Result := WideExpandFileName(FileName);
if (Length(Result) >= 3) and (Result[2] = ':') and (Upcase(char(Result[1])) >= 'A')
and (Upcase(char(Result[1])) <= 'Z') then
Result := WideGetUniversalName(Result);
end;
function WideGetUniversalName(const FileName: WideString): WideString;
var Size: LongWord; RemoteNameInfo: array[0..1023] of Byte;
begin
Result := FileName;
if (Win32Platform <> VER_PLATFORM_WIN32_WINDOWS) or (Win32MajorVersion > 4) then begin
Size := SizeOf(RemoteNameInfo);
if WNetGetUniversalNameW(PWideChar(FileName), UNIVERSAL_NAME_INFO_LEVEL, @RemoteNameInfo, Size) <> NO_ERROR then Exit;
Result := PRemoteNameInfoW(@RemoteNameInfo).lpUniversalName;
end
end;
function SplitLine(var Line: WideString): WideString;
var i: integer;
begin
i := Pos(#32, Line);
if (length(Line) < 72) or (i < 1) then begin
Result := Line;
Line := '';
exit;
end;
if (i > 71) then begin
Result := Copy(Line, 1, i - 1);
Delete(Line, 1, i);
exit;
end;
i := 72; while Line[i] <> #32 do dec(i);
Result := Copy(Line, 1, i - 1);
Delete(Line, 1, i);
end;
procedure AddChain(var Count: integer; var rs: WideString; const s: WideString);
begin
inc(Count);
if rs = '' then rs := s
else rs := rs + ',' + s;
end;
function CheckOption(OPTN: WideString): boolean;
begin
OPTN := Tnt_WideLowerCase(OPTN); Result := False;
if OPTN = '-fs' then begin
WantFullscreen := True; Result := True; end;
if OPTN = '-compact' then begin
WantCompact := True; Result := True; end;
if OPTN = '-autoquit' then begin
AutoQuit := True; Result := True; end;
if OPTN = '-enqueue' then Result := True;
end;
function EscapeParam(const Param: widestring): widestring;
begin
if Pos(#32, Param) > 0 then Result := #34 + Param + #34 else Result := Param;
end;
function SecondsToTime(Seconds: integer): string;
var m, s: integer;
begin
if Seconds < 0 then Seconds := 0;
m := (Seconds div 60) mod 60;
s := Seconds mod 60;
Result := IntToStr(Seconds div 3600)
+ ':' + char(48 + m div 10) + char(48 + m mod 10)
+ ':' + char(48 + s div 10) + char(48 + s mod 10);
end;
function TimeToSeconds(TimeCode: string): integer;
begin
Result := (StrToIntDef(copy(TimeCode, 1, 2), 0) * 60 + StrToIntDef(copy(TimeCode, 4, 2), 0)) * 60 + StrToIntDef(copy(TimeCode, 7, 2), 0);
end;
function CheckInfo(const Map: array of WideString; Value: WideString): integer;
var i: integer;
begin
if Value <> '' then
for i := Low(Map) to High(Map) do
if Map[i] = Value then begin
Result := i;
exit;
end;
Result := -1;
end;
function CheckSubfont(Sfont: WideString): WideString;
var i: integer;
begin
if WideFileExists(ExpandName(HomeDir, Sfont)) then begin
Result := Sfont;
if not IsWideStringMappableToAnsi(Sfont) then Result := WideExtractShortPathName(Sfont);
end
else begin
Result := ''; Sfont := Trim(Tnt_WideLowerCase(Sfont));
for i := 0 to FontPaths.Count - 1 do begin
if (Sfont = Tnt_WideLowerCase(OptionsForm.CSubfont.Items[i])) or (Sfont = FontPaths[i]) then begin
Result := ExpandName(SystemDir + 'fonts\', FontPaths[i]);
exit;
end;
end;
if Result = '' then begin
if DefaultFontIndex > -1 then Result := ExpandName(SystemDir + 'fonts\', FontPaths[DefaultFontIndex])
else if FileExists(SystemDir + 'fonts\arial.ttf') then
Result := SystemDir + 'fonts\arial.ttf'
else if WideFileExists(HomeDir + 'mplayer\subfont.ttf') then begin
if IsWideStringMappableToAnsi(HomeDir + 'mplayer\subfont.ttf') then
Result := HomeDir + 'mplayer\subfont.ttf'
else
Result := WideExtractShortPathName(HomeDir + 'mplayer\subfont.ttf');
end;
end;
end;
end;
function ColorToStr(Color: Longint): WideString;
var i: integer; s: WideString;
begin
Result := '';
s := Tnt_WideFormat('%.8x', [Color]);
for i := length(s) downto 1 do Result := Result + s[i];
end;
procedure SetLastPos;
begin
if not HaveVideo then
LastPos := SecondPos
else begin
if SecondPos < 15 then
LastPos := SecondPos - 5
else
LastPos := SecondPos - 15;
end;
end;
function GetFolderPath(csidl: integer): WideString;
var Buffer: PAnsiChar; BufferW: PWideChar;
begin
if Win32PlatformIsUnicode then begin
new(BufferW);
if SHGetSpecialFolderPathW(0, BufferW, csidl, false) then
Result := BufferW
else Result := '';
dispose(BufferW);
end
else begin
new(Buffer);
if SHGetSpecialFolderPath(0, Buffer, csidl, false) then
Result := WideString(Buffer)
else Result := '';
dispose(Buffer);
end;
end;
procedure Init;
const RFID_APPDATA: TGUID = '{3EB685DB-65F9-4CF6-A03A-E3EF65729F3D}';
RFID_PERSONAL: TGUID = '{FDD39AD0-238F-46AF-ADB4-6C85480369C7}';
// use by SHGetKnownFolderPath http://msdn.microsoft.com/en-us/library/bb762584(VS.85).aspx
begin
SystemDir := Tnt_WideLowerCase(WideIncludeTrailingPathDelimiter(WideGetEnvironmentVariable('windir')));
TempDir := WideIncludeTrailingPathDelimiter(WideGetEnvironmentVariable('TEMP')) + 'MPUI\';
HomeDir := Tnt_WideLowerCase(WideIncludeTrailingPathDelimiter(WideExtractFileDir(WideExpandFileName(WideParamStr(0)))));
if Win32PlatformIsVista then AppdataDir := GetShellPath(RFID_APPDATA)
else AppdataDir := GetFolderPath(CSIDL_APPDATA);
if AppdataDir = '' then AppdataDir := HomeDir else AppdataDir := WideIncludeTrailingPathDelimiter(AppdataDir);
if Win32PlatformIsVista then ShotDir := GetShellPath(RFID_PERSONAL)
else ShotDir := GetFolderPath(CSIDL_PERSONAL);
if ShotDir = '' then ShotDir := TempDir + 'MPUISnap' else ShotDir := WideIncludeTrailingPathDelimiter(ShotDir) + 'MPUISnap';
WadspL:= HomeDir + 'plugins\dsp_enh.dll';
LyricDir := ShotDir;
MplayerLocation := HomeDir + 'mplayer.exe';
MWC := Windows.GetSystemMetrics(SM_CYCAPTION);
GetLocaleFormatSettings(GetUserDefaultLCID, FormatSet);
if Pos('ddd', FormatSet.ShortDateFormat) = 0 then FormatSet.ShortDateFormat := 'ddd ' + FormatSet.ShortDateFormat;
if Pos('ddd', FormatSet.LongDateFormat) = 0 then FormatSet.LongDateFormat := 'dddd ' + FormatSet.LongDateFormat;
SetErrorMode(SEM_FAILCRITICALERRORS);
//SetThreadLocale(LOCALE_SYSTEM_DEFAULT);
{//在user_def和sys_def不同时,为了使mpui能够正常播放sys_def的文件添加了这句,但菜单可能显示不正常。
原因就是string和widestring在ansi环境下默认转化造成的。}
Load(HomeDir + DefaultFileName, 1);
end;
procedure Start;
var DummyPipe1, DummyPipe2: THandle;
si: TStartupInfoW;
pi: TProcessInformation;
sec: TSecurityAttributes;
CmdLine, S, a,n, afChain: WideString;
Success: boolean; Error: DWORD;
ErrorMessage: array[0..1023] of Char;
ErrorMessageW: array[0..1023] of WideChar;
i, t, h: integer; UnRART: TUnRARThread; m:TMenuItem;
begin
if Running or (length(MediaURL) = 0) then exit;
Status := sOpening; IsPause := false; IsDx := false;
if FirstOpen then begin
MainForm.LTime.Caption := '';
MainForm.LStatus.Caption := LOCstr_Status_Opening;
end;
FirstChance := true; afChain := ''; h := 0;
ClientWaitThread := TClientWaitThread.Create(true);
ClientWaitThread.FreeOnTerminate := true;
Processor := TProcessor.Create(true);
Processor.FreeOnTerminate := true;
if ML then CmdLine := EscapeParam(ExpandName(HomeDir, MplayerLocation))
else CmdLine := EscapeParam(HomeDir + 'mplayer.exe');
if not GUI then CmdLine := CmdLine + ' -nogui -noconsolecontrols';
CmdLine := CmdLine + ' -slave -identify -noquiet -nofs -noterm-osd -hr-mp3-seek'
+ ' -subalign 1 -spualign 1 -sub-fuzziness 0 -subfont-autoscale 2'
+ ' -subfont-osd-scale 4.8 -subfont-text-scale ' + FloatToStr(FSize)
+ ' -subfont-outline ' + FloatToStr(Fol) + ' -subfont-blur ' + FloatToStr(FB);
if uav then CmdLine := CmdLine + ' -lavdopts threads=' + avThread;
if AudioFile <> '' then CmdLine := CmdLine + ' -audiofile ' + EscapeParam(AudioFile);
if Async then CmdLine := CmdLine + ' -autosync ' + AsyncV;
if Pri then begin
CmdLine := CmdLine + ' -priority abovenormal';
SetPriorityClass(GetCurrentProcess, HIGH_PRIORITY_CLASS);
end
else SetPriorityClass(GetCurrentProcess, ABOVE_NORMAL_PRIORITY_CLASS);
CurMonitor := Screen.MonitorFromWindow(MainForm.Handle);
MonitorID := CurMonitor.MonitorNum; MonitorW := CurMonitor.Width; MonitorH := CurMonitor.Height;
if not CurMonitor.Primary then CmdLine := CmdLine + ' -adapter ' + IntToStr(MonitorID);
if nmsg then CmdLine := CmdLine + ' -nomsgmodule';
if UseUni then CmdLine := CmdLine + ' -msgcharset noconv';
if Fd then CmdLine := CmdLine + ' -framedrop';
if ni then CmdLine := CmdLine + ' -ni';
if nobps then CmdLine := CmdLine + ' -nobps';
if ReIndex then CmdLine := CmdLine + ' -idx';
if SoftVol then begin
if mute then CmdLine := CmdLine + ' -softvol -softvol-max 1000 -volume 0'
else CmdLine := CmdLine + ' -softvol -softvol-max 1000 -volume ' + IntToStr(Volume div 10);
end
else begin
if mute then CmdLine := CmdLine + ' -volume 0'
else CmdLine := CmdLine + ' -volume ' + IntToStr(Volume);
end;
MainForm.UpdateVolSlider;
if Uni then CmdLine := CmdLine + ' -unicode';
if Utf then CmdLine := CmdLine + ' -utf8';
if lavf then CmdLine := CmdLine + ' -demuxer lavf';
if vsync then CmdLine := CmdLine + ' -vsync';
if Wid and Win32PlatformIsUnicode then
CmdLine := CmdLine + ' -colorkey 0x101010 -nokeepaspect' + ' -wid ' + IntToStr(MainForm.IPanel.Handle)
else if ontop > 0 then CmdLine := CmdLine + ' -ontop';
if OSDLevel <> 1 then CmdLine := CmdLine + ' -osdlevel ' + IntToStr(OSDLevel);
if Dr then CmdLine := CmdLine + ' -dr';
if dbbuf then CmdLine := CmdLine + ' -double';
if nfc then CmdLine := CmdLine + ' -nofontconfig';
if Ass then begin
CmdLine := CmdLine + ' -ass'; SubPos := Dsubpos;
if Efont then CmdLine := CmdLine + ' -embeddedfonts';
CmdLine := CmdLine + ' -ass-color ' + ColorToStr(TextColor)
+ ' -ass-border-color ' + ColorToStr(OutColor)
+ ' -ass-font-scale ' + FloatToStr(FSize / Fscale);
if ISub then CmdLine := CmdLine + ' -vf-pre ass';
end;
s := CheckSubfont(subfont);
if uof then begin
if s <> '' then CmdLine := CmdLine + ' -subfont ' + EscapeParam(s);
s := CheckSubfont(osdfont);
end;
if s <> '' then CmdLine := CmdLine + ' -font ' + EscapeParam(s);
case Expand of
0: if ISub and (not Ass) then CmdLine := CmdLine + ' -vf-pre expand=osd=1 -noslices';
1: if ISub and (not Ass) then CmdLine := CmdLine + ' -vf-pre expand=:-80::40:1 -noslices'
else CmdLine := CmdLine + ' -vf-pre expand=:-80::40';
2: if ISub and (not Ass) then CmdLine := CmdLine + ' -vf-pre expand=::::1:4/3 -noslices'
else CmdLine := CmdLine + ' -vf-pre expand=aspect=4/3';
end;
if Flip then CmdLine := CmdLine + ' -vf-add flip';
if Mirror then CmdLine := CmdLine + ' -vf-add mirror';
case Rot of
1: CmdLine := CmdLine + ' -vf-add rotate=1';
2: CmdLine := CmdLine + ' -vf-add rotate=2';
end;
s := Trim(LowerCase(VideoOut));
if s <> '' then begin
if s = 'novideo' then CmdLine := CmdLine + ' -novideo'
else if s = 'null' then CmdLine := CmdLine + ' -vo null'
else if s <> 'auto' then CmdLine := CmdLine + ' -vo ' + s + ',';
end;
if not Dda then begin
if Yuy2 then CmdLine := CmdLine + ' -vf-add yuy2';
if Eq2 then CmdLine := CmdLine + ' -vf-add eq2';
case Deinterlace of
1: CmdLine := CmdLine + ' -vf-add pp=fd';
2: CmdLine := CmdLine + ' -vf-add kerndeint';
end;
end;
if Speed <> 1 then CmdLine := CmdLine + ' -speed ' + FloatToStr(Speed);
if Adelay <> 0 then CmdLine := CmdLine + ' -delay ' + FloatToStr(Adelay);
if Sdelay <> 0 then CmdLine := CmdLine + ' -subdelay ' + FloatToStr(Sdelay);
if SPDIF then CmdLine := CmdLine + ' -afm hwac3';
case Postproc of
1: CmdLine := CmdLine + ' -autoq 10 -vf-add pp';
2: CmdLine := CmdLine + ' -vf-add pp=ac';
end;
case AudioOut of
0: CmdLine := CmdLine + ' -nosound';
1: CmdLine := CmdLine + ' -ao null';
3: CmdLine := CmdLine + ' -ao win32,';
4: if OptionsForm.CAudioDev.ItemIndex > -1 then CmdLine := CmdLine + ' -ao dsound:device=' + IntToStr(AudioDev) + ',';
end;
case Ch of
1: CmdLine := CmdLine + ' -channels 4';
2: CmdLine := CmdLine + ' -channels 6';
3: CmdLine := CmdLine + ' -channels 8';
end;
if Firstrun then begin
ClearTmpFiles(TempDir); Lyric.ClearLyric; procArc := true; CheckMediaInfo;
a:=WideIncludeTrailingPathDelimiter(ExpandName(HomeDir, LyricDir));
s := Tnt_WideLowerCase(WideExtractFileExt(MediaURL));
n:= WideExtractFileName(MediaURL);
ArcMovie := DisplayURL;
i:= CheckInfo(MediaType, s);
if (i > -1) and (i <= ZipTypeCount) then begin
i := Pos(':', DisplayURL);
if i > 0 then ArcPW := copy(DisplayURL, i + 1, length(DisplayURL) - i)
else ArcPW := '';
i := Pos(' <-- ', DisplayURL);
if i > 0 then ArcMovie := copy(DisplayURL, 1, i - 1);
end
else i := -1;
TmpURL := Tnt_WideLowerCase(GetFileName(ArcMovie));
if WideFileExists(LyricURL) then begin //拖放的歌词或用户指定的歌词
s := WideExtractFileName(LyricURL);
s := Tnt_WideLowerCase(GetFileName(s));
if TmpURL = s then Lyric.ParseLyric(LyricURL);
end;
loadLyricSub(MediaURL);
loadLyricSub(a + n);
if HaveLyric = 0 then loadArcLyric(MediaURL);
if LoadVob = 0 then begin
TmpURL := loadArcSub(MediaURL);
if TmpURL <> '' then begin
Vobfile := TmpURL; LoadVob := 1; end;
end;
if HaveLyric = 0 then loadArcLyric(a,n);
if LoadVob = 0 then begin
TmpURL := loadArcSub(a,n);
if TmpURL <> '' then begin
Vobfile := TmpURL; LoadVob := 1; end;
end;
if i>0 then begin
n:= WideExtractFileDir(MediaURL);
loadLyricSub(n,ArcMovie);
loadLyricSub(a,ArcMovie);
if HaveLyric = 0 then loadArcLyric(n,ArcMovie);
if LoadVob = 0 then begin
TmpURL := loadArcSub(n,ArcMovie);
if TmpURL <> '' then begin
Vobfile := TmpURL; LoadVob := 1; end;
end;
if HaveLyric = 0 then loadArcLyric(a,ArcMovie);
if LoadVob = 0 then begin
TmpURL := loadArcSub(a,ArcMovie);
if TmpURL <> '' then begin
Vobfile := TmpURL; LoadVob := 1; end;
end;
end;
if (i > 0) and IsLoaded(s) then begin
tEnd := false;
TmpURL := MediaURL; //避免系统调度UNRART线程的不确定性造成线程执行时获取的是已经变化的MediaURL
MediaURL := TempDir + ArcMovie;
UnRART := TUnRARThread.Create(true);
UnRART.FreeOnTerminate := true;
UnRART.Priority := tpTimeCritical;
UNRART.Resume;
SwitchToThread;
while not tEnd do begin
Application.ProcessMessages;
if WideFileExists(MediaURL) then begin
WaitForSingleObject(UnRART.Handle,1000);
break;
end;
end;
if not WideFileExists(MediaURL) then begin
MainForm.LStatus.Caption := ''; Status := sNone;
exit;
end;
end;
end;
{ ______________________________________________________________________
| vob (-vob vobfile) | ID_VOBSUB_ID | | |
|______________________________|________________| VobAndInterSubCount |
| inter (DVD/MKV/OGM) | ID_SUBTITLE_ID | | |
|______________________________|________________|___|__ |
| lastsub (-sub substring) | | | |
| | | Lastsubcount CurrentSub
| (re)start | | |__ |
|______________________________| |______| | |
| autoloaded Sub | | | |
| (samedirSub) | ID_FILE_SUB_ID | SubCount |
| (re)start | | | |
|______________________________| |_________|____________|
| running (sub_load) loadsub=1 | | |__|
|______________________________|________________|______|
}
if Loadsrt > 0 then begin //必须放到LoadVOB的判断前面,因为要考虑到VOB字幕加载失败时需要对SubID进行调整
if Loadsrt = 1 then begin
if (SubID >= (VobAndInterSubCount + Lastsubcount)) and (SubID < CurrentSubCount) then
SubID := SubID + (subcount - Lastsubcount) //Adjust location of subtitles autoloaded调整自动加载的外部字幕的位置
else
if SubID >= CurrentSubCount then //Adjust location of subtitles recently loaded调整新近加载的外部字幕的位置
SubID := SubID - (CurrentSubCount - Lastsubcount - VobAndInterSubCount);
Lastsubcount := subcount;
Loadsrt := 2;
end;
if substring <> '' then CmdLine := CmdLine + ' -sub ' + substring;
end;
if (LoadVob > 0) and (LoadVob < 3) then begin //必须放到Loadsrt的判断后面,因为要考虑到VOB字幕加载失败时需要对SubID进行调整
if LoadVob = 1 then begin
LoadVob := 3; SubID := SubID - VobsubCount; //考虑到VOB字幕加载失败时需要对SubID进行调整
end;
if Vobfile <> '' then begin
s := Vobfile;
if not IsWideStringMappableToAnsi(s) then begin
s := WideExtractShortPathName(Vobfile + '.idx'); s := GetFileName(s);
end;
CmdLine := CmdLine + ' -vobsub ' + EscapeParam(s);
end;
end;
if (VideoID >= 0) then CmdLine := CmdLine + ' -vid ' + IntToStr(VideoID);
if (AudioID >= 0) and (AudioOut > 0) then CmdLine := CmdLine + ' -aid ' + IntToStr(AudioID);
if subcode <> '' then begin
if Pos(' (', subcode) > 0 then
CmdLine := CmdLine + ' -subcp ' + copy(subcode, 1, Pos(' (', subcode) - 1)
else CmdLine := CmdLine + ' -subcp ' + subcode;
end;
if MAspect <> '' then begin
if Trim(LowerCase(MAspect)) = 'default' then
CmdLine := CmdLine + ' -monitoraspect ' + IntTostr(CurMonitor.Width) + ':' + IntTostr(CurMonitor.Height)
else CmdLine := CmdLine + ' -monitoraspect ' + MAspect; OptionsForm.CAspect.Items.Count
end;
if Aspect = MainForm.MAspects.Count - 1 then begin
if InterW > 3 * InterH then InterW := 3 * InterH;
CmdLine := CmdLine + ' -aspect ' + IntToStr(InterW) + ':' + IntToStr(InterH);
end
else if Aspect > 0 then CmdLine := CmdLine + ' -aspect ' + OptionsForm.CAspect.Items[Aspect];
if Wadsp then begin
s := ExpandName(HomeDir, WadspL);
h := pos(':', s); a := '';
if h > 0 then begin
t := pos(':', copy(s, h + 1, MaxInt));
if t > 0 then begin
a := copy(s, h + t, MaxInt); s := copy(s, 1, h + t - 1);
end;
end;
if WideFileExists(s) then begin
if (not IsWideStringMappableToAnsi(s)) or (pos(',', s) > 0) then s := WideExtractShortPathName(s);
if sconfig or (a <> '') then AddChain(h, afChain, 'wadsp=' + EscapeParam(s) + ':cfg=1')
else AddChain(h, afChain, 'wadsp=' + EscapeParam(s));
end;
end;
if Volnorm then AddChain(h, afChain, 'volnorm=2');
if afChain <> '' then CmdLine := CmdLine + ' -af ' + afChain;