summaryrefslogtreecommitdiff
path: root/plugins/Watrack/players/pl_vlc.pas
blob: f9bf7f0342b5a66af0953922ff093f2c3dda4283 (plain)
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
{Video Lan player}
unit pl_VLC;
{$include compilers.inc}

interface

implementation
uses windows,common,srv_player,wat_api,syswin,wrapper
  {$IFDEF DELPHI_7_UP}
  ,variants
  {$ENDIF}
  {$IFDEF KOL_MCK}
  ,kolcomobj
  {$ELSE}
  ,mComObj
  {$ENDIF}
;

{
    procedure play; safecall;
    procedure pause; safecall;
    procedure stop; safecall;
    procedure playlistNext; safecall;
    procedure playlistPrev; safecall;
    property Playing: WordBool read Get_Playing;
    property Position: Single read Get_Position write Set_Position;
    property Time: SYSINT read Get_Time write Set_Time;
    property Length: SYSINT read Get_Length;
    (0)1-97(100)
    property Volume: SYSINT read Get_Volume write Set_Volume;
    property VersionInfo: WideString read Get_VersionInfo;
}

const
//  GuidOld: TGUID = '{E23FE9C6-778E-49D4-B537-38FCDE4887D8}';
  VLCClass = 'wxWindowClassNR';
  VLCName  = 'VLC media player';
  COMName  = 'VideoLAN.VLCPlugin.1'; // IVLCControl

//  GuidNew: TGUID = '{9BE31822-FDAD-461B-AD51-BE1D1C159921}';
  VLCClassSkin = 'SkinWindowClass';
  VLCClassNew  = 'QWidget';
  VLCEXEName   = 'VLC.EXE';
  COMNameNew   = 'VideoLAN.VLCPlugin2'; // IVLCControl2

function Check(wnd:HWND;flags:integer):HWND;cdecl;
var
  tmp,EXEName:PAnsiChar;
begin
  if wnd<>0 then
  begin
    result:=0;
    exit;
  end;
  result:=FindWindow(VLCClass,VLCName);
  if result=0 then
    result:=FindWindow(VLCClassSkin,nil); // VLCName
  if result=0 then
    result:=FindWindow(VLCClassNew,nil);
  if result<>0 then
  begin
    tmp:=Extract(GetEXEByWnd(result,EXEName),true);
    if lstrcmpia(tmp,VLCEXEName)<>0 then
      result:=0;
    mFreeMem(tmp);
    mFreeMem(EXEName);
  end;
{  if result<>0 then
  begin
    tmp:=Extract(GetEXEByWnd(result,EXEName),true);
    if lstrcmpia(tmp,'VLC.EXE')<>0 then
      result:=0;
    mFreeMem(tmp);
    mFreeMem(EXEName);
  end;
}
end;

function SplitVersion(p:pWideChar):integer;
begin
  result:=StrToInt(p);
  while (p^>='0') and (p^<='9') do inc(p); inc(p);
  result:=result*16+StrToInt(p);
  while (p^>='0') and (p^<='9') do inc(p); inc(p);
  result:=(result*16+StrToInt(p))*16;
  while (p^>='0') and (p^<='9') do inc(p); inc(p);
  result:=result*16+StrToInt(p);
end;

function GetVersion(const ver:pWideChar):integer;
begin
  try
    result:=SplitVersion(ver);
  except
    result:=0;
  end;
end;

function GetVersionText(const v:variant):PWideChar;
begin
  try
    StrDupW(result,PWideChar(WideString(v.VersionInfo)));
  except
    result:=nil;
  end;
end;

function GetWndText(wnd:HWND):pWideChar;
var
  p:pWideChar;
begin
  result:=GetDlgText(wnd);
{
need to clear  " - lalala VLC" at the end
}
  if result<>nil then
  begin
    p:=StrRScanW(result,'-');
    if p<>nil then // found
    begin
      if (p>result) and ((p-1)^=' ') and ((p+1)^=' ') then
        (p-1)^:=#0;
    end;
  end;
end;

{
function GetTotalTime:integer;
var
  v:variant;
begin
  try
    v:=CreateOleObject(COMName);
    result:=v.Length;
  except
    result:=inherited GetTotalTime;
  end;
  v:=Null;
end;

function GetElapsedTime:integer;
var
  v:variant;
begin
  try
    v:=CreateOleObject(COMName);
    result:=v.Time;
  except
    result:=inherited GetElapsedTime;
  end;
  v:=Null;
end;

function GetStatus:integer; cdecl;
var
  v:variant;
  tmp:boolean;
begin
  try
    v:=CreateOleObject(COMName);
    tmp:=v.Playing;
    if tmp then
      result:=WAT_MES_PLAYING
    else
      result:=WAT_MES_STOPPED;
  except
    result:=inherited GetStatus;
  end;
  v:=Null;
end;

function Play(fname:PWideChar=nil):integer;
var
  v:variant;
begin
  try
    v:=CreateOleObject(COMName);
    result:=v.play;
  except
    result:=inherited Play(fname);
  end;
  v:=Null;
end;

function Pause:integer;
var
  v:variant;
begin
  try
    v:=CreateOleObject(COMName);
    result:=v.pause;
  except
    result:=inherited Pause;
  end;
  v:=Null;
end;

function Stop:integer;
var
  v:variant;
begin
  try
    v:=CreateOleObject(COMName);
    result:=v.stop;
  except
    result:=inherited Stop;
  end;
  v:=Null;
end;

function Next:integer;
var
  v:variant;
begin
  try
    v:=CreateOleObject(COMName);
    result:=v.playlistNext;
  except
    result:=inherited Next;
  end;
  v:=Null;
end;

function Prev:integer;
var
  v:variant;
begin
  try
    v:=CreateOleObject(COMName);
    result:=v.playlistPrev;
  except
    result:=inherited Prev;
  end;
  v:=Null;
end;

function Seek(value:integer):integer;
var
  v:variant;
begin
  try
    v:=CreateOleObject(COMName);
    result:=v.Position;
    if value>0 then
      v.Position:=value
    else
      result:=0;
  except
    result:=inherited Seek(value);
  end;
  v:=Null;
end;

function GetVolume:cardinal;
var
  v:variant;
begin
  try
    v:=CreateOleObject(COMName);
    result:=v.Volume;
    result:=(result shl 16)+((result shl 4) div 100);
  except
    result:=0;
  end;
  v:=Null;
end;

procedure SetVolume(value:cardinal);
var
  v:variant;
begin
  try
    v:=CreateOleObject(COMName);
    v.Volume:=(value*100) shr 4;
    end;
  except
    result:=inherited SetVolume(value);
  end;
  v:=Null;
end;

function VolDn:integer;
var
  val:integer;
begin
  result:=GetVolume;
  val:=loword(result);
  if val>0 then
    SetVolume(val-1);
end;

function VolUp:integer;
var
  val:integer;
begin
  result:=GetVolume;
  val:=loword(result);
  if val<16 then
    SetVolume(val+1);
end;

}
function GetInfo(var SongInfo:tSongInfo;flags:integer):integer;cdecl;
var
  v:variant;
begin
  result:=0;
  if (flags and WAT_OPT_PLAYERDATA)<>0 then
  begin
    if SongInfo.plyver=0 then
    begin
      try
        try
          v:=CreateOleObject(COMName);
        except
          try
            v:=CreateOleObject(COMNameNew);
          except
            v:=Null;
          end;
        end;
        if v<>Null then
          with SongInfo do
          begin
            txtver:=GetVersionText(v);
            plyver:=GetVersion(txtver);
          end;
      except
      end;
      v:=Null;
      if (flags and WAT_OPT_CHANGES)<>0 then
        SongInfo.wndtext:=GetWndText(SongInfo.plwnd);
    end;
  end;
end;
{
function Command(wnd:HWND;cmd:integer;value:integer):integer;cdecl;
begin
  result:=0;
  case cmd of
    WAT_CTRL_PREV : result:=Prev;
    WAT_CTRL_PLAY : result:=Play(pWideChar(value));
    WAT_CTRL_PAUSE: result:=Pause;
    WAT_CTRL_STOP : result:=Stop;
    WAT_CTRL_NEXT : result:=Next;
    WAT_CTRL_VOLDN: result:=VolDn;
    WAT_CTRL_VOLUP: result:=VolUp;
    WAT_CTRL_SEEK : result:=Seek(value);
  end;
end;
}
const
  plRec:tPlayerCell=(
    Desc     :'VideoLAN player';
    flags    :WAT_OPT_HASURL;
    Icon     :0;
    Init     :nil;
    DeInit   :nil;
    Check    :@Check;
    GetStatus:nil;
    GetName  :nil;
    GetInfo  :@GetInfo;
    Command  :nil;
    URL      :'http://www.videolan.org/';
    Notes    :nil);

var
  LocalPlayerLink:twPlayer;

procedure InitLink;
begin
  LocalPlayerLink.Next:=PlayerLink;
  LocalPlayerLink.This:=@plRec;
  PlayerLink          :=@LocalPlayerLink;
end;

initialization
//  ServicePlayer(WAT_ACT_REGISTER,dword(@plRec));
  InitLink;
end.