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
|
{iTunes player}
unit pl_iTunes;
{$include compilers.inc}
interface
implementation
uses windows,common,srv_player,wat_api
{$IFDEF DELPHI_7_UP}
,variants
{$ENDIF}
{$IFDEF KOL_MCK}
,kolcomobj
{$ELSE}
,ComObj
{$ENDIF}
;
const
iTunesClass = 'iTunes';
iTunesTitle = 'iTunes';
COMName = 'iTunes.Application';
function Check(wnd:HWND;flags:integer):HWND;cdecl;
begin
if wnd<>0 then
begin
result:=0;
exit;
end;
result:=FindWindow(iTunesClass,iTunesTitle);
end;
function GetFileName(wnd:HWND;flags:integer):PWideChar;cdecl;
var
v:variant;
begin
try
v:=CreateOleObject(COMName);
StrDupW(result,PWideChar(WideString(v.CurrentTrack.Location)));
except
result:=nil;
end;
v:=Null;
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
if (ver<>nil) and (ver^<>#0) then
result:=SplitVersion(ver)
else
result:=0;
end;
function GetVersionText(const v:variant):PWideChar;
begin
try
StrDupW(result,PWideChar(WideString(v.Version)));
except
result:=nil;
end;
end;
function GetTotalTime(const v:variant):integer;
begin
try
result:=v.CurrentTrack.Duration;
except
result:=0;
end;
end;
function GetElapsedTime(const v:variant):integer;
begin
try
result:=v.PlayerPosition;
except
result:=0;
end;
end;
function GetStatus(wnd:HWND):integer; cdecl;
var
tmp:integer;
v:variant;
begin
try
v:=CreateOleObject(COMName);
tmp:=v.PlayerState;
if tmp=1 then
result:=WAT_MES_PLAYING
else
result:=WAT_MES_STOPPED;
except
result:=WAT_MES_UNKNOWN;
end;
v:=Null;
end;
function GetKbps(const v:variant):integer;
begin
try
result:=v.CurrentTrack.BitRate;
except
result:=0;
end;
end;
function GetKhz(const v:variant):integer;
begin
try
result:=v.CurrentTrack.SampleRate;
except
result:=0;
end;
end;
function GetTrack(const v:variant):integer;
begin
try
result:=v.CurrentTrack.TrackNumber;
except
result:=0;
end;
end;
function GetAlbum(const v:variant):pWideChar;
begin
try
StrDupW(result,PWideChar(WideString(v.CurrentTrack.Album)));
except
result:=nil;
end;
end;
function GetYear(const v:variant):pWideChar;
begin
try
StrDupW(result,PWideChar(WideString(v.CurrentTrack.Year)));
except
result:=nil;
end;
end;
function GetGenre(const v:variant):pWideChar;
begin
try
StrDupW(result,PWideChar(WideString(v.CurrentTrack.Genre)));
except
result:=nil;
end;
end;
function GetArtist(const v:variant):pWideChar;
begin
try
StrDupW(result,PWideChar(WideString(v.CurrentTrack.Artist)));
except
result:=nil;
end;
end;
function GetTitle(const v:variant):pWideChar;
begin
try
StrDupW(result,PWideChar(WideString(v.CurrentStreamTitle)));
except
result:=nil;
end;
end;
function GetComment(const v:variant):pWideChar;
begin
try
StrDupW(result,PWideChar(WideString(v.CurrentTrack.Comment)));
except
result:=nil;
end;
end;
function GetWndText(const v:variant):pWideChar;
begin
try
StrDupW(result,PWideChar(WideString(v.Windows.Name)));
except
result:=nil;
end;
end;
function Play(const v:variant;fname:PWideChar=nil):integer;
begin
try
// v.PlayFile(fname);
v.BackTrack;
result:=v.Play;
except
result:=0;
end;
end;
function Pause(const v:variant):integer;
begin
try
result:=v.PlayPause;
except
result:=0;
end;
end;
function Stop(const v:variant):integer;
begin
try
result:=v.Stop;
except
result:=0;
end;
end;
function Next(const v:variant):integer;
begin
try
result:=v.NextTrack;
except
result:=0;
end;
end;
function Prev(const v:variant):integer;
begin
try
result:=v.PreviousTrack;
except
result:=0;
end;
end;
function Seek(const v:variant;value:integer):integer;
begin
try
result:=v.PlayerPosition;
if value>0 then
v.PlayerPosition:=value
else
result:=0;
except
result:=0;
end;
end;
function GetVolume(const v:variant):cardinal;
begin
try
result:=v.SoundVolume;
result:=(result shl 16)+round((result shl 4)/100);
except
result:=0;
end;
end;
procedure SetVolume(const v:variant;value:cardinal);
begin
try
v.SoundVolume:=integer((value*100) shr 4);
except
end;
end;
function VolDn(const v:variant):integer;
var
val:integer;
begin
result:=GetVolume(v);
val:=loword(result);
if val>0 then
SetVolume(v,val-1);
end;
function VolUp(const v:variant):integer;
var
val:integer;
begin
result:=GetVolume(v);
val:=loword(result);
if val<16 then
SetVolume(v,val+1);
end;
function GetInfo(var SongInfo:tSongInfo;flags:integer):integer;cdecl;
var
v:variant;
begin
result:=0;
with SongInfo do
begin
try
v:=CreateOleObject(COMName);
if (flags and WAT_OPT_PLAYERDATA)<>0 then
begin
if plyver=0 then
begin
txtver:=GetVersionText(v);
plyver:=GetVersion(txtver);
end;
end
else if (flags and WAT_OPT_CHANGES)<>0 then
begin
volume:=GetVolume(v);
if status<>WAT_MES_STOPPED then
time:=GetElapsedTime(v);
end
else
begin
if total =0 then total :=GetTotalTime(v);
if track =0 then track :=GetTrack(v);
if year =NIL then year :=GetYear(v);
if genre =NIL then genre :=GetGenre(v);
if artist =NIL then artist :=GetArtist(v);
if album =NIL then album :=GetAlbum(v);
if comment=NIL then comment:=GetComment(v);
if kbps =0 then kbps :=GetKbps(v);
if khz =0 then khz :=GetKhz(v);
end;
// wndtext:=GetWndText(v);
except
end;
v:=Null;
// if title=NIL then title:=GetTitle; // only for streaming audio
end;
end;
function Command(wnd:HWND;cmd:integer;value:int_ptr):integer;cdecl;
var
v:Variant;
begin
result:=0;
try
v:=CreateOleObject(COMName);
case cmd of
WAT_CTRL_PREV : result:=Prev (v);
WAT_CTRL_PLAY : result:=Play (v,pWideChar(value));
WAT_CTRL_PAUSE: result:=Pause(v);
WAT_CTRL_STOP : result:=Stop (v);
WAT_CTRL_NEXT : result:=Next (v);
WAT_CTRL_VOLDN: result:=VolDn(v);
WAT_CTRL_VOLUP: result:=VolUp(v);
WAT_CTRL_SEEK : result:=Seek (v,value);
end;
except
end;
v:=Null;
end;
const
plRec:tPlayerCell=(
Desc :'iTunes';
flags :WAT_OPT_SINGLEINST or WAT_OPT_HASURL;
Icon :0;
Init :nil;
DeInit :nil;
Check :@Check;
GetStatus:@GetStatus;
GetName :@GetFileName;
GetInfo :@GetInfo;
Command :@Command;
URL :'http://www.itunes.com/';
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.
|