Debian Codegraph @

plugins/wlx/wmp/src/wmp.lpr

raw
1 {
2 Double commander
3 -------------------------------------------------------------------------
4 Windows Media Player plugin
5
6 Copyright (C) 2021-2024 Alexander Koblov ([email protected])
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 }
21
22 library wmp;
23
24 {$mode objfpc}{$H+}
25
26 uses
27 Classes, WMPLib_1_0_TLB, ActiveXContainer, SysUtils, Windows, WlxPlugin,
28 IniFiles;
29
30 const
31 CLASS_NAME = UnicodeString('IWMPPlayer4');
32
33 var
34 Volume: Integer = 50;
35 ConfigFile: AnsiString;
36
37 procedure LoadConfiguration;
38 begin
39 try
40 with TIniFile.Create(ConfigFile) do
41 try
42 Volume:= ReadInteger('WMP', 'Volume', Volume);
43 finally
44 Free;
45 end;
46 except
47 // Ignore
48 end;
49 end;
50
51 procedure SaveConfiguration;
52 begin
53 try
54 with TIniFile.Create(ConfigFile) do
55 try
56 WriteInteger('WMP', 'Volume', Volume);
57 finally
58 Free;
59 end;
60 except
61 // Ignore
62 end;
63 end;
64
65 function ListLoadW(ParentWin: HWND; FileToLoad: PWideChar; ShowFlags: Integer): HWND; stdcall;
66 var
67 ARect: TRect;
68 APlayer: IWMPPlayer4;
69 AData: TActiveXContainer;
70 WindowClassW: TWndClassW;
71 begin
72 try
73 APlayer:= CoWindowsMediaPlayer.Create;
74 except
75 Exit(wlxInvalidHandle);
76 end;
77
78 ZeroMemory(@WindowClassW, SizeOf(WndClassW));
79 with WindowClassW do
80 begin
81 Style := CS_DBLCLKS;
82 lpfnWndProc := @DefWindowProc;
83 cbWndExtra := SizeOf(Pointer);
84 hCursor := LoadCursor(0, IDC_ARROW);
85 lpszClassName := CLASS_NAME;
86 hInstance := GetModuleHandleW(nil);
87 end;
88 Windows.RegisterClassW(WindowClassW);
89
90 if not GetClientRect(ParentWin, ARect) then
91 ARect:= TRect.Create(0, 0, 640, 480);
92
93 Result:= CreateWindowW(CLASS_NAME, 'PreviewHandler', WS_CHILD or WS_VISIBLE, ARect.Left, ARect.Top,
94 ARect.Right, ARect.Bottom, ParentWin, 0, WindowClassW.hInstance, nil);
95
96 if (Result <> wlxInvalidHandle) then
97 begin
98 AData:= TActiveXContainer.Create(nil);
99 AData.Handle:= Result;
100 AData.ComServer:= APlayer;
101 try
102 AData.Active:= True;
103 APlayer.settings.volume:= Volume;
104 APlayer.URL:= WideString(FileToLoad);
105 APlayer.Controls.Play;
106 except
107 AData.Free;
108 DestroyWindow(Result);
109 Result:= wlxInvalidHandle;
110 end;
111 end;
112 end;
113
114 procedure ListCloseWindow(ListWin: HWND); stdcall;
115 var
116 AVolume: Integer;
117 AData: TActiveXContainer;
118 AHandle: THandle absolute AData;
119 begin
120 AHandle:= GetWindowLongPtr(ListWin, GWLP_USERDATA);
121 if Assigned(AData) then
122 begin
123 AVolume:= (AData.ComServer as IWMPPlayer4).settings.volume;
124 if AVolume <> Volume then
125 begin
126 Volume:= AVolume;
127 SaveConfiguration;
128 end;
129 AData.Free;
130 end;
131 DestroyWindow(ListWin);
132 end;
133
134 function ListLoadNextW(ParentWin, PluginWin: HWND; FileToLoad: PWideChar; ShowFlags: Integer): Integer; stdcall;
135 var
136 APlayer: IWMPPlayer4;
137 AData: TActiveXContainer;
138 AHandle: THandle absolute AData;
139 begin
140 AHandle:= GetWindowLongPtr(PluginWin, GWLP_USERDATA);
141 if Assigned(AData) then
142 begin
143 APlayer:= AData.ComServer as IWMPPlayer4;
144 try
145 APlayer.Controls.Stop;
146 APlayer.URL:= WideString(FileToLoad);
147 APlayer.Controls.Play;
148 except
149 Exit(LISTPLUGIN_ERROR);
150 end;
151 end;
152 Result:= LISTPLUGIN_OK;
153 end;
154
155 procedure ListSetDefaultParams(dps: PListDefaultParamStruct); stdcall;
156 begin
157 // Save configuration file name
158 ConfigFile:= dps^.DefaultIniName;
159 LoadConfiguration;
160 end;
161
162 procedure ListGetDetectString(DetectString: PAnsiChar; MaxLen: Integer); stdcall;
163 begin
164 StrLCopy(DetectString, '(EXT="WAV")|(EXT="MP3")|(EXT="WMA")|(EXT="MP4")|(EXT="AVI")|(EXT="WMV")', MaxLen);
165 end;
166
167 exports
168 ListLoadW,
169 ListLoadNextW,
170 ListCloseWindow,
171 ListGetDetectString,
172 ListSetDefaultParams;
173
174 end.
175