CnWinampCtrl.pas 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. {******************************************************************************}
  2. { CnPack For Delphi/C++Builder }
  3. { 中国人自己的开放源码第三方开发包 }
  4. { (C)Copyright 2001-2018 CnPack 开发组 }
  5. { ------------------------------------ }
  6. { }
  7. { 本开发包是开源的自由软件,您可以遵照 CnPack 的发布协议来修 }
  8. { 改和重新发布这一程序。 }
  9. { }
  10. { 发布这一开发包的目的是希望它有用,但没有任何担保。甚至没有 }
  11. { 适合特定目的而隐含的担保。更详细的情况请参阅 CnPack 发布协议。 }
  12. { }
  13. { 您应该已经和开发包一起收到一份 CnPack 发布协议的副本。如果 }
  14. { 还没有,可访问我们的网站: }
  15. { }
  16. { 网站地址:http://www.cnpack.org }
  17. { 电子邮件:master@cnpack.org }
  18. { }
  19. {******************************************************************************}
  20. unit CnWinampCtrl;
  21. {* |<PRE>
  22. ================================================================================
  23. * 软件名称:不可视工具组件包
  24. * 单元名称:Winamp控制器组件TCnWinampCtrl单元
  25. * 单元作者:小冬 (kendling@21cn.com)
  26. * 备 注:- 可以控制Winamp的一个小小控件。
  27. * - 可以用本控件写一个基本上可以完全控制Winamp的软件。
  28. * - 可以用本控件开发一个歌词编辑器。
  29. * 开发平台:PWin2000 + Delphi 6.0 Update Pack 2
  30. * 兼容测试:PWin2000 + Delphi 6.0 Update Pack 2
  31. * 本 地 化:该单元中没有字符串资源
  32. * 单元标识:$Id$
  33. * 修改记录:
  34. * 2005.03.08 v1.0
  35. * 创建单元
  36. ================================================================================
  37. |</PRE>}
  38. interface
  39. {$I CnPack.inc}
  40. uses
  41. //------------------------------------------------------------------------------
  42. // System
  43. //------------------------------------------------------------------------------
  44. SysUtils, Classes, Messages, Windows, ShellAPI,
  45. //------------------------------------------------------------------------------
  46. // CnPack
  47. //------------------------------------------------------------------------------
  48. CnCommon, CnClasses, CnConsts, CnCompConsts;
  49. const
  50. WinampClassName = 'Winamp v1.x';
  51. //------------------------------------------------------------------------------
  52. // WA IPC
  53. //------------------------------------------------------------------------------
  54. WM_WA_IPC = WM_USER;
  55. IPC_GETVERSION = 0;
  56. IPC_PLAYFILE = 100;
  57. IPC_ENQUEUEFILE = 100;
  58. IPC_DELETE = 101;
  59. IPC_CHDIR = 103;
  60. IPC_ISPLAYING = 104;
  61. IPC_GETOUTPUTTIME = 105;
  62. IPC_JUMPTOTIME = 106;
  63. IPC_WRITEPLAYLIST = 120;
  64. IPC_SETPLAYLISTPOS = 121;
  65. IPC_SETVOLUME = 122;
  66. IPC_SETPANNING = 123;
  67. IPC_GETLISTLENGTH = 124;
  68. IPC_GETLISTPOS = 125;
  69. IPC_GETINFO = 126;
  70. IPC_GETEQDATA = 127;
  71. IPC_SETEQDATA = 128;
  72. IPC_RESTARTWINAMP = 135;
  73. IPC_CHANGECURRENTFILE = 245;
  74. IPC_GET_SHUFFLE = 250;
  75. IPC_GET_REPEAT = 251;
  76. IPC_SET_SHUFFLE = 252;
  77. IPC_SET_REPEAT = 253;
  78. IPC_ENABLEDISABLE_ALL_WINDOWS = 259;
  79. IPC_GETWND = 260;
  80. IPC_GETWND_EQ = 0;
  81. IPC_GETWND_PE = 1;
  82. IPC_GETWND_MB = 2;
  83. IPC_GETWND_VIDEO = 3;
  84. WINAMP_FILE_QUIT = 40001;
  85. WINAMP_OPTIONS_EQ = 40036;
  86. WINAMP_OPTIONS_PLEDIT = 40040;
  87. WINAMP_BUTTON1 = 40044;
  88. WINAMP_BUTTON2 = 40045;
  89. WINAMP_BUTTON3 = 40046;
  90. WINAMP_BUTTON4 = 40047;
  91. WINAMP_BUTTON5 = 40048;
  92. WINAMP_VOLUMEUP = 40058;
  93. WINAMP_VOLUMEDOWN = 40059;
  94. WINAMP_FFWD5S = 40060;
  95. WINAMP_REW5S = 40061;
  96. WINAMP_BUTTON1_SHIFT = 40144;
  97. WINAMP_BUTTON2_SHIFT = 40145;
  98. WINAMP_BUTTON3_SHIFT = 40146;
  99. WINAMP_BUTTON4_SHIFT = 40147;
  100. WINAMP_BUTTON5_SHIFT = 40148;
  101. WINAMP_BUTTON1_CTRL = 40154;
  102. WINAMP_BUTTON2_CTRL = 40155;
  103. WINAMP_BUTTON3_CTRL = 40156;
  104. WINAMP_BUTTON4_CTRL = 40157;
  105. WINAMP_BUTTON5_CTRL = 40158;
  106. IDC_SORT_FILENAME = 40166;
  107. IDC_SORT_FILETITLE = 40167;
  108. IDC_SORT_ENTIREFILENAME = 40168;
  109. WINAMP_JUMP10FWD = 40195;
  110. WINAMP_JUMP10BACK = 40197;
  111. WINAMP_MAIN_WINDOW = 40258;
  112. WINAMP_MINIMIZE = 40334;
  113. //------------------------------------------------------------------------------
  114. // WA PE
  115. //------------------------------------------------------------------------------
  116. type
  117. TEQDataSelect = (EQ60hz, EQ170hz, EQ310hz, EQ600hz, EQ1k, EQ3k,EQ6k, EQ12k,
  118. EQ14k, EQ16k, EQPreAmp, EQEnabled, EQAutoLoad);
  119. //==============================================================================
  120. // Winamp控制器对象
  121. //==============================================================================
  122. { TWinampControl }
  123. TCnWinampCtrl = class(TCnComponent)
  124. {* Winamp控制器组件}
  125. private
  126. FAutoFind: Boolean;
  127. FAutoWritePlayList: Boolean;
  128. FStartDelay: Integer;
  129. FWAPath: string;
  130. FWndWinamp: HWND;
  131. function GetEQData(const Index: TEQDataSelect): Byte;
  132. function GetIsFound: Boolean;
  133. function GetPlayListPos: Integer;
  134. function GetVolume: Byte;
  135. function GetVolBalance: Integer;
  136. function GetWACurrentTime: Integer;
  137. function GetWARepeat: Boolean;
  138. function GetWAShufle: Boolean;
  139. function GetWAState: Integer;
  140. function SendMessageToWinamp(Msg: Cardinal; wParam: WPARAM; lParam:
  141. LPARAM): Integer;
  142. procedure SetEnabledWAWindow(const Value: Boolean);
  143. procedure SetEQData(const Index: TEQDataSelect; const Value: Byte);
  144. procedure SetPlayListPos(const Value: Integer);
  145. procedure SetVolume(const Value: Byte);
  146. procedure SetVolBalance(const Value: Integer);
  147. procedure SetWACurrentTime(const Value: Integer);
  148. procedure SetWARepeat(const Value: Boolean);
  149. procedure SetWAShufle(const Value: Boolean);
  150. protected
  151. procedure GetComponentInfo(var AName, Author, Email, Comment: string); override;
  152. public
  153. constructor Create(AOwner: TComponent); override;
  154. {* 类构造器}
  155. destructor Destroy; override;
  156. {* 类析构器}
  157. procedure AddDir(const strPath: string);
  158. {* 添加目录到播放列表最后}
  159. procedure AddFile(const strPath: string);
  160. {* 添加文件到播放列表最后}
  161. procedure ClearPlayList;
  162. {* 清除播放列表}
  163. procedure CloseWinamp;
  164. {* 关闭Winamp}
  165. function FindWinamp: Boolean;
  166. {* 查找Winamp窗口句柄}
  167. procedure FFW_5sec;
  168. {* 向前5秒}
  169. function GetInfo(const iMode: Integer): Integer;
  170. {* 获取当前歌曲信息 iMode为 0:采样率 1:比特率 2:通道 3:视频 LOWORD=w HIWORD=h 4:> 65536, string (视频描述)}
  171. function GetPlayList: string;
  172. {* 获取Winamp当前播放列表 返回格式为TString.CommaText}
  173. procedure GetPlayListCount;
  174. {* 获取播放曲目总数}
  175. function GetTimeLength: Integer;
  176. {* 获取当前歌曲总时间}
  177. function GetVersion: string;
  178. {* 获取Winamp版本}
  179. procedure JUMP10BACK;
  180. {* 向后10秒}
  181. procedure JUMP10FWD;
  182. {* 向前10秒}
  183. procedure NextTack;
  184. {* 下一首歌曲}
  185. procedure Pause;
  186. {* 暂停播放}
  187. procedure Play;
  188. {* 开始播放}
  189. procedure PlayIndex(const Index: Integer);
  190. {* 播放列表中的一首歌}
  191. procedure PlayListSortInFileName;
  192. {* 播放列表以文件名排序}
  193. procedure PlayListSortInFilePath;
  194. {* 播放列表以路径和文件名排序}
  195. procedure PlayListSortInTitle;
  196. {* 播放列表以标题排序}
  197. procedure PrevTrack;
  198. {* 上一首歌曲}
  199. procedure RestartWinamp;
  200. {* 重新启动Winamp}
  201. procedure REW_5sec;
  202. {* 向后5秒}
  203. function StartWinamp(const strWAPath: string=''): Boolean;
  204. {* 启动Winamp}
  205. procedure Stop;
  206. {* 停止播放}
  207. procedure VolumeDown;
  208. {* 减少一点音量 测试中2.95可用,5.08不可用}
  209. procedure VolumeUp;
  210. {* 增加一点音量 测试中2.95可用,5.08不可用}
  211. procedure WritePlayList;
  212. {* 保存当前播放列表到Winamp程序的目录}
  213. property EnabledWAWindow: Boolean write SetEnabledWAWindow;
  214. {* 开启/屏蔽Winamp所有窗口,对新面板无效。}
  215. property EQData[const Index: TEQDataSelect]: Byte read GetEQData write
  216. SetEQData; default;
  217. {* EQ数据 Index为: EQPreAmp, EQ60hz, EQ170hz, EQ310hz, EQ600hz, EQ1k, EQ3k,
  218. EQ6k, EQ12k, EQ14k, EQ16k, EQEnabled, EQAutoLoad EQPreAmp..EQ16k:0-63
  219. EQEnabled/EQAutoLoad为0时关闭,非0时开启。}
  220. property IsFound: Boolean read GetIsFound default False;
  221. {* 当前是否已经找到Winamp窗口句柄}
  222. property PlayListPos: Integer read GetPlayListPos write SetPlayListPos;
  223. {* 播放列表所选的位置}
  224. property Volume: Byte read GetVolume write SetVolume;
  225. {* Winamp音量 0 - 255}
  226. property VolBalance: Integer read GetVolBalance write SetVolBalance;
  227. {* 音量平行 -127 - 127}
  228. property WACurrentTime: Integer read GetWACurrentTime write SetWACurrentTime;
  229. {* 歌曲播放的当前时间 单位ms}
  230. property WARepeat: Boolean read GetWARepeat write SetWARepeat;
  231. {* 获取/设置循环播放}
  232. property WAShufle: Boolean read GetWAShufle write SetWAShufle;
  233. {* 获取/设置随机播放}
  234. property WAState: Integer read GetWAState;
  235. {* 获取Winamp当前状态 返回值:0 为停止 1 为正在播放 3 为暂停}
  236. published
  237. property AutoFind: Boolean read FAutoFind write FAutoFind default False;
  238. {* 自动查找Winamp窗口句柄}
  239. property AutoWritePlayList: Boolean read FAutoWritePlayList write
  240. FAutoWritePlayList default False;
  241. {* 自动保存播放列表}
  242. property StartDelay: Integer read FStartDelay write FStartDelay default 3000;
  243. {* 等待Winamp启动的延时}
  244. property WAPath: string read FWAPath write FWAPath;
  245. {* Winamp程序路径 如: C:\Program Files\Winamp\Winamp.exe}
  246. end;
  247. implementation
  248. //==============================================================================
  249. // Winamp控制器对象
  250. //==============================================================================
  251. constructor TCnWinampCtrl.Create(AOwner: TComponent);
  252. begin
  253. inherited;
  254. FStartDelay := 3000;
  255. if FAutoFind then FindWinamp;
  256. end;
  257. destructor TCnWinampCtrl.Destroy;
  258. begin
  259. inherited;
  260. end;
  261. procedure TCnWinampCtrl.AddDir(const strPath: string);
  262. var
  263. PPath: PChar;
  264. cds : COPYDATASTRUCT;
  265. begin
  266. PPath := PChar(strPath);
  267. cds.dwData := IPC_CHDIR;
  268. cds.lpData := PPath;
  269. cds.cbData := SysUtils.StrLen(PAnsiChar(cds.lpData))+1; // include space for null char
  270. SendMessageToWinamp(WM_COPYDATA, WPARAM(0), LPARAM(@cds));
  271. if FAutoFind then WritePlayList;
  272. end;
  273. procedure TCnWinampCtrl.AddFile(const strPath: string);
  274. var
  275. PPath: PChar;
  276. cds : COPYDATASTRUCT;
  277. begin
  278. PPath := PChar(strPath);
  279. cds.dwData := IPC_PLAYFILE;
  280. cds.lpData := PPath;
  281. cds.cbData := SysUtils.StrLen(PAnsiChar(cds.lpData))+1; // include space for null char
  282. SendMessageToWinamp(WM_COPYDATA, WPARAM(0), LPARAM(@cds));
  283. if FAutoFind then WritePlayList;
  284. end;
  285. procedure TCnWinampCtrl.ClearPlayList;
  286. begin
  287. SendMessageToWinamp(WM_WA_IPC, 0, IPC_DELETE);
  288. if FAutoFind then WritePlayList;
  289. end;
  290. procedure TCnWinampCtrl.CloseWinamp;
  291. begin
  292. SendMessageToWinamp(WM_COMMAND, WINAMP_FILE_QUIT ,0);
  293. FWndWinamp := 0;
  294. end;
  295. function TCnWinampCtrl.FindWinamp: Boolean;
  296. begin
  297. FWndWinamp := FindWindow(WinampClassName, nil);
  298. Result := IsFound;
  299. end;
  300. procedure TCnWinampCtrl.FFW_5sec;
  301. begin
  302. SendMessageToWinamp(WM_COMMAND, WINAMP_FFWD5S, 0);
  303. end;
  304. procedure TCnWinampCtrl.GetComponentInfo(var AName, Author, Email, Comment:
  305. string);
  306. begin
  307. AName := SCnWinampCtrlName;
  308. Author := SCnPack_Kendling;
  309. Email := SCnPack_KendlingEmail;
  310. Comment := SCnWinampCtrlComment;
  311. end;
  312. function TCnWinampCtrl.GetEQData(const Index: TEQDataSelect): Byte;
  313. begin
  314. Result := SendMessageToWinamp(WM_WA_IPC, Ord(Index), IPC_GETEQDATA);
  315. end;
  316. function TCnWinampCtrl.GetInfo(const iMode: Integer): Integer;
  317. begin
  318. Result := SendMessageToWinamp(WM_WA_IPC, iMode, IPC_GETINFO);
  319. end;
  320. function TCnWinampCtrl.GetPlayList: string;
  321. var
  322. slPlayList, slCPlayList: TStrings;
  323. i, j: Integer;
  324. begin
  325. {检测是否设置了Winamp路径}
  326. Result := '';
  327. if not FileExists(FWAPath) then Exit;
  328. if FAutoFind then WritePlayList;
  329. {获取当前播放列表}
  330. slPlayList := TStringList.Create;
  331. slCPlayList := TStringList.Create;
  332. slPlayList.LoadFromFile(_CnChangeFileExt(FWAPath, '.m3u'));
  333. if UpperCase(slPlayList[0]) = '#EXTM3U' then
  334. begin
  335. i := 1;
  336. while i < slPlayList.Count do
  337. begin
  338. if UpperCase(Copy(slPlayList[i], 1, 7)) = '#EXTINF' then
  339. begin
  340. j := AnsiPos(',', slPlayList[i]);
  341. slCPlayList.Add(Copy(slPlayList[i], j+1, 256));
  342. Inc(i);
  343. end else
  344. begin
  345. slCPlayList.Add(_CnExtractFileName(slPlayList[i]));
  346. end;
  347. Inc(i);
  348. end;
  349. {输出播放列表}
  350. Result := slCPlayList.CommaText;
  351. end;
  352. slPlayList.Free;
  353. slCPlayList.Free;
  354. end;
  355. function TCnWinampCtrl.GetIsFound: Boolean;
  356. begin
  357. Result := FWndWinamp <> 0; //INVALID_HANDLE_VALUE [DWord(-1)]; 2005.3.7 QQCAT
  358. end;
  359. procedure TCnWinampCtrl.GetPlayListCount;
  360. begin
  361. SendMessageToWinamp(WM_WA_IPC, 0, IPC_GETLISTLENGTH);
  362. end;
  363. function TCnWinampCtrl.GetPlayListPos: Integer;
  364. begin
  365. Result := SendMessageToWinamp(WM_WA_IPC, 0, IPC_GETLISTPOS);
  366. end;
  367. function TCnWinampCtrl.GetTimeLength: Integer;
  368. begin
  369. Result := SendMessageToWinamp(WM_WA_IPC, 1, IPC_GETOUTPUTTIME);
  370. end;
  371. function TCnWinampCtrl.GetVersion: string;
  372. begin
  373. Result := IntToHex(SendMessageToWinamp(WM_WA_IPC, 0, IPC_GETVERSION), 2);
  374. if Result = '00' then
  375. begin
  376. Result := '0';
  377. Exit;
  378. end;
  379. if Result[1] = '2' then Result[3] := Result[2];
  380. if Result[1] = '1' then Result[3] := Result[2];
  381. Result[2] := '.';
  382. end;
  383. function TCnWinampCtrl.GetVolume: Byte;
  384. begin
  385. Result := SendMessageToWinamp(WM_WA_IPC, WPARAM(-666), IPC_SETVOLUME);
  386. end;
  387. function TCnWinampCtrl.GetVolBalance: Integer;
  388. begin
  389. Result := SendMessageToWinamp(WM_WA_IPC, WPARAM(-666), IPC_SETPANNING);
  390. end;
  391. function TCnWinampCtrl.GetWACurrentTime: Integer;
  392. begin
  393. Result := SendMessageToWinamp(WM_WA_IPC, 0, IPC_GETOUTPUTTIME);
  394. end;
  395. function TCnWinampCtrl.GetWARepeat: Boolean;
  396. begin
  397. Result := SendMessageToWinamp(WM_WA_IPC, 0, IPC_GET_REPEAT)>0;
  398. end;
  399. function TCnWinampCtrl.GetWAShufle: Boolean;
  400. begin
  401. Result := SendMessageToWinamp(WM_WA_IPC, 0, IPC_GET_SHUFFLE)>0;
  402. end;
  403. function TCnWinampCtrl.GetWAState: Integer;
  404. begin
  405. Result := SendMessageToWinamp(WM_WA_IPC, 0, IPC_ISPLAYING);
  406. end;
  407. procedure TCnWinampCtrl.JUMP10BACK;
  408. begin
  409. SendMessageToWinamp(WM_COMMAND, WINAMP_JUMP10BACK, 0);
  410. end;
  411. procedure TCnWinampCtrl.JUMP10FWD;
  412. begin
  413. SendMessageToWinamp(WM_COMMAND, WINAMP_JUMP10FWD, 0);
  414. end;
  415. procedure TCnWinampCtrl.NextTack;
  416. begin
  417. SendMessageToWinamp(WM_COMMAND, WINAMP_BUTTON5, 0);
  418. end;
  419. procedure TCnWinampCtrl.Pause;
  420. begin
  421. SendMessageToWinamp(WM_COMMAND, WINAMP_BUTTON3, 0);
  422. end;
  423. procedure TCnWinampCtrl.Play;
  424. begin
  425. SendMessageToWinamp(WM_COMMAND, WINAMP_BUTTON2, 0);
  426. end;
  427. procedure TCnWinampCtrl.PlayIndex(const Index: Integer);
  428. begin
  429. SendMessageToWinamp(WM_WA_IPC, WPARAM(Index), IPC_CHANGECURRENTFILE);
  430. end;
  431. procedure TCnWinampCtrl.PlayListSortInFileName;
  432. begin
  433. SendMessageToWinamp(WM_COMMAND, IDC_SORT_FILENAME, 0);
  434. end;
  435. procedure TCnWinampCtrl.PlayListSortInFilePath;
  436. begin
  437. SendMessageToWinamp(WM_COMMAND, IDC_SORT_ENTIREFILENAME, 0);
  438. end;
  439. procedure TCnWinampCtrl.PlayListSortInTitle;
  440. begin
  441. SendMessageToWinamp(WM_COMMAND, IDC_SORT_FILETITLE, 0);
  442. end;
  443. procedure TCnWinampCtrl.PrevTrack;
  444. begin
  445. SendMessageToWinamp(WM_COMMAND, WINAMP_BUTTON1, 0);
  446. end;
  447. procedure TCnWinampCtrl.RestartWinamp;
  448. begin
  449. SendMessageToWinamp(WM_WA_IPC, 0, IPC_RESTARTWINAMP);
  450. end;
  451. procedure TCnWinampCtrl.REW_5sec;
  452. begin
  453. SendMessageToWinamp(WM_COMMAND, WINAMP_REW5S, 0);
  454. end;
  455. function TCnWinampCtrl.SendMessageToWinamp(Msg: Cardinal; wParam: WPARAM;
  456. lParam: LPARAM): Integer;
  457. begin
  458. Result := 0;
  459. if not IsFound then Exit;
  460. Result := SendMessage(FWndWinamp, Msg, wParam, lParam);
  461. end;
  462. procedure TCnWinampCtrl.SetEnabledWAWindow(const Value: Boolean);
  463. begin
  464. if Value then
  465. SendMessageToWinamp(WM_WA_IPC, 0, IPC_ENABLEDISABLE_ALL_WINDOWS)
  466. else
  467. SendMessageToWinamp(WM_WA_IPC, WPARAM($DEADBEEF), IPC_ENABLEDISABLE_ALL_WINDOWS);
  468. end;
  469. procedure TCnWinampCtrl.SetEQData(const Index: TEQDataSelect; const Value:
  470. Byte);
  471. begin
  472. SendMessageToWinamp(WM_WA_IPC, Ord(Index), IPC_GETEQDATA);
  473. SendMessageToWinamp(WM_WA_IPC, Value, IPC_SETEQDATA);
  474. end;
  475. procedure TCnWinampCtrl.SetPlayListPos(const Value: Integer);
  476. begin
  477. SendMessageToWinamp(WM_WA_IPC, Value, IPC_SETPLAYLISTPOS)
  478. end;
  479. procedure TCnWinampCtrl.SetVolume(const Value: Byte);
  480. begin
  481. SendMessageToWinamp(WM_WA_IPC, Value, IPC_SETVOLUME);
  482. end;
  483. procedure TCnWinampCtrl.SetVolBalance(const Value: Integer);
  484. begin
  485. SendMessageToWinamp(WM_WA_IPC, Value, IPC_SETPANNING);
  486. end;
  487. procedure TCnWinampCtrl.SetWACurrentTime(const Value: Integer);
  488. begin
  489. SendMessageToWinamp(WM_WA_IPC, Value, IPC_JUMPTOTIME);
  490. end;
  491. procedure TCnWinampCtrl.SetWARepeat(const Value: Boolean);
  492. begin
  493. SendMessageToWinamp(WM_WA_IPC, Integer(Value), IPC_SET_REPEAT);
  494. end;
  495. procedure TCnWinampCtrl.SetWAShufle(const Value: Boolean);
  496. begin
  497. SendMessageToWinamp(WM_WA_IPC, Integer(Value), IPC_SET_SHUFFLE);
  498. end;
  499. function TCnWinampCtrl.StartWinamp(const strWAPath: string=''): Boolean;
  500. begin
  501. Result := False;
  502. if strWAPath <> '' then FWAPath := strWAPath;
  503. if not FileExists(FWAPath) then Exit;
  504. if ShellExecute(0, '', PChar(FWAPath), PChar('/CLASS="'+WinAmpClassName+'"'),
  505. PChar(_CnExtractFilePath(FWAPath)), SW_MINIMIZE) > 32 then
  506. Result := True;
  507. if FAutoFind then
  508. begin
  509. Sleep(FStartDelay);
  510. FindWinamp;
  511. end;
  512. end;
  513. procedure TCnWinampCtrl.Stop;
  514. begin
  515. SendMessageToWinamp(WM_COMMAND, WINAMP_BUTTON4, 0);
  516. end;
  517. procedure TCnWinampCtrl.VolumeDown;
  518. begin
  519. SendMessageToWinamp(WM_COMMAND, WINAMP_VOLUMEDOWN, 0);
  520. end;
  521. procedure TCnWinampCtrl.VolumeUp;
  522. begin
  523. SendMessageToWinamp(WM_COMMAND, WINAMP_VOLUMEUP, 0);
  524. end;
  525. procedure TCnWinampCtrl.WritePlayList;
  526. begin
  527. SendMessageToWinamp(WM_WA_IPC, 0, IPC_WRITEPLAYLIST);
  528. end;
  529. end.