unit Unit1;
interface
uses
Windows, Messages,Registry, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,shellapi, ExtCtrls, MPlayer;
type
TForm1 = class(TForm)
Panel1: TPanel;
OpenDialog1: TOpenDialog;
MediaPlayer1: TMediaPlayer;
procedure FormCreate(Sender: TObject);
procedure MediaPlayer1Click(Sender: TObject; Button: TMPBtnType;
var DoDefault: Boolean);
procedure MediaPlay(PlayFile:string);
procedure FormShow(Sender: TObject);
procedure Panel1DblClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
const
cMyExe = '.mp3'; //文件扩展名
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var
Reg: TRegistry;
begin
Reg := TRegistry.Create;
try
Reg.RootKey :=HKEY_CLASSES_ROOT;
// Reg.OpenKey(cMyExe+'/DefaultIcon', True);
// Reg.WriteString('', Application.ExeName + ',0');
reg.OpenKey(cMyExe,true);
reg.WriteString('','myfile');
Reg.CloseKey;
Reg.OpenKey('myfile/shell/open/command', True);
Reg.WriteString('',Application.ExeName + ' %1');
Reg.CloseKey;
finally
Reg.Free;
end;
end;
procedure TForm1.MediaPlayer1Click(Sender: TObject; Button: TMPBtnType;
var DoDefault: Boolean);
begin
try
if Button=btPlay then
begin
MediaPlay(mediaplayer1.FileName);
end;
except
showmessage('error');
end;
end;
procedure TForm1.MediaPlay(PlayFile: string);
begin
with mediaplayer1 do begin
FileName:=PlayFile;
AutoEnable:=true;
AutoRewind:=true;
Open;
Play;
end;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
if paramstr(1)<>'' then begin
MediaPlay(paramstr(1));
end;
end;
procedure TForm1.Panel1DblClick(Sender: TObject);
begin
try
if OpenDialog1.Execute then
MediaPlay(OpenDialog1.FileName);
except
showmessage('error');
end;
end;
end.