www.pudn.com > DirectShowPlayer.rar > AMPU3.PAS
// Avalon Media Player
// Copyright © 2001 Pulsar Studio / Lord Trancos.
unit AMPU3;
// --------------------------------------------------------------------
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, Common;
type
TForm3 = class(TForm)
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
CheckBox1: TCheckBox;
ListBox1: TListBox;
BitBtn3: TBitBtn;
BitBtn4: TBitBtn;
BitBtn5: TBitBtn;
BitBtn6: TBitBtn;
BitBtn7: TBitBtn;
OpenDialog2: TOpenDialog;
CheckBox2: TCheckBox;
procedure BitBtn3Click(Sender: TObject);
procedure BitBtn4Click(Sender: TObject);
procedure BitBtn5Click(Sender: TObject);
procedure BitBtn6Click(Sender: TObject);
procedure BitBtn7Click(Sender: TObject);
procedure CheckBox1Click(Sender: TObject);
procedure ListBox1DblClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
function AddFilesToPlayList(_clearPlaylist: boolean): longint;
procedure ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
procedure CheckBox2Click(Sender: TObject);
procedure WMSysCommand(var msg: TMessage); message WM_SYSCOMMAND;
function GetCurrentItem: string;
procedure SetCurrentItem(_fn: string);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form3 : TForm3;
// --------------------------------------------------------------------
implementation
uses AMPU1;
{$R *.DFM}
// --------------------------------------------------------------------
procedure TForm3.WMSysCommand(var msg: TMessage);
begin
if msg.WParam = SC_MINIMIZE then Application.Minimize else inherited;
end;
// --------------------------------------------------------------------
function TForm3.GetCurrentItem: string;
begin
if (CurrentIdx > -1) and (CurrentIdx < ListBox1.Items.Count)
then Result := ListBox1.Items[CurrentIdx] else Result := ''
end;
// --------------------------------------------------------------------
procedure TForm3.SetCurrentItem(_fn: string);
begin
if (_fn <> '') then
begin
CurrentIdx := ListBox1.Items.IndexOf(_fn);
Form3.Listbox1.Repaint;
end;
end;
// --------------------------------------------------------------------
function TForm3.AddFilesToPlayList(_clearPlaylist: boolean): longint;
var _cnt : longint;
begin
Result := -1;
EnableWindow(Form1.Handle, false);
try
if OpenDialog2.Execute then
if OpenDialog2.Files.Count > 0 then
begin
while GetAsyncKeystate(VK_LBUTTON) <> 0 do ;
if _clearPlaylist then ListBox1.Clear;
ListBox1.Perform(WM_SETREDRAW, 0, 0);
for _cnt := 0 to OpenDialog2.Files.Count - 1 do
begin
if ListBox1.Items.IndexOf(OpenDialog2.Files[_cnt]) = -1
then ListBox1.Items.Add(OpenDialog2.Files[_cnt]);
if _cnt = 0
then Result := ListBox1.Items.IndexOf(OpenDialog2.Files[_cnt]);
end;
ListBox1.Perform(WM_SETREDRAW, 1, 0);
end;
finally
Application.ProcessMessages;
EnableWindow(Form1.Handle, true);
end;
end;
// --------------------------------------------------------------------
procedure TForm3.BitBtn3Click(Sender: TObject);
// Load playlist.
begin
if OpenDialog1.Execute then
begin
ListBox1.Items.LoadFromFile(OpenDialog1.Filename);
CurrentIdx := -1;
Form3.Listbox1.Repaint;
end;
end;
// --------------------------------------------------------------------
procedure TForm3.BitBtn4Click(Sender: TObject);
// Save playlist.
begin
if SaveDialog1.Execute
then ListBox1.Items.SaveToFile(SaveDialog1.Filename);
end;
// --------------------------------------------------------------------
procedure TForm3.BitBtn5Click(Sender: TObject);
// Add folder to playlist.
var _dir : string;
_fn : string;
_sd : boolean;
_i : integer;
begin
_dir := ChooseDir(Handle, NIL);
if (_dir <> '') then
begin
// Include sub-directories ?
_i := Application.MessageBox(MSG01, MSG00,
MB_YESNO + MB_ICONQUESTION);
_sd := (_i = IDYES);
// Get current item.
_fn := GetCurrentItem;
// Add files.
ListBox1.Perform(WM_SETREDRAW, 0, 0);
AddDirToList(_dir, ListBox1.Items, _sd);
ListBox1.Perform(WM_SETREDRAW, 1, 0);
// Restore item.
SetCurrentItem(_fn);
end;
end;
// --------------------------------------------------------------------
procedure TForm3.BitBtn6Click(Sender: TObject);
// Add files to playlist.
var _fn : string;
begin
_fn := GetCurrentItem; // Get current item.
AddFilesToPlayList(false); // add files
SetCurrentItem(_fn); // Restore item.
end;
// --------------------------------------------------------------------
procedure TForm3.BitBtn7Click(Sender: TObject);
// Remove files from playlist.
var _cnt : longint;
_fn : string;
begin
if ListBox1.SelCount > 0 then
begin
// Get current item.
_fn := GetCurrentItem;
// Delete selected items.
ListBox1.Perform(WM_SETREDRAW, 0, 0);
for _cnt := ListBox1.Items.Count-1 downto 0 do
if ListBox1.Selected[_cnt] then ListBox1.Items.Delete(_cnt);
ListBox1.Perform(WM_SETREDRAW, 1, 0);
// Restore item.
SetCurrentItem(_fn);
end;
end;
// --------------------------------------------------------------------
procedure TForm3.CheckBox1Click(Sender: TObject);
// Sort ?
begin
ListBox1.Sorted := CheckBox1.Checked;
SendMessage(ListBox1.Handle, LB_SETHORIZONTALEXTENT, 1024, 0);
end;
// --------------------------------------------------------------------
procedure TForm3.CheckBox2Click(Sender: TObject);
// Show path ?
begin
ListBox1.Repaint;
end;
// --------------------------------------------------------------------
procedure TForm3.ListBox1DblClick(Sender: TObject);
// Play selected file.
begin
if ListBox1.ItemIndex > -1 then
begin
CurrentIdx := ListBox1.ItemIndex;
CurrentFile := ListBox1.Items[CurrentIdx];
Form3.Listbox1.Repaint;
Form1.LoadAndPlay;
end;
end;
// --------------------------------------------------------------------
procedure TForm3.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var _fn : string;
begin
with (Control as TListBox).Canvas do
begin
if Index = CurrentIdx then
begin
Brush.Color := clRed;
Font.Color := clWhite;
end;
FillRect(Rect);
if not CheckBox2.Checked
then _fn := ExtractFileName((Control as TListBox).Items[Index])
else _fn := (Control as TListBox).Items[Index];
TextOut(Rect.Left + 2, Rect.Top, _fn);
end;
end;
// --------------------------------------------------------------------
procedure TForm3.FormCreate(Sender: TObject);
begin
SendMessage(ListBox1.Handle, LB_SETHORIZONTALEXTENT, 1024, 0);
end;
// --------------------------------------------------------------------
end.