📄 mp3.pas
字号:
TrayIcon.Free;
end;
procedure TMP3Player.BtnBackClick(Sender: TObject);
var
CurPosition: Integer;
begin
if (MediaPlayer1.Mode= mpPlaying) or (MediaPlayer1.Mode= mpPaused) then
begin
CurPosition:= MediaPlayer1.Position;
MediaPlayer1.Stop;
if CurPosition-3000> 0then
MediaPlayer1.StartPos:= CurPosition- 3000
else
MediaPlayer1.StartPos:= 0;
MediaPlayer1.Play;
if nSec- 4< 0 then
begin
nSec:= nSec + 60- 4;
nMin:= nMin- 1;
end
else
begin
nSec:= nSec- 4;
end;
end;
end;
function TMP3Player.MilliSecondsToString(Length: Integer): String;
var
nSeconds, nMinites: Integer;
strMinites, strSeconds, strTime: String;
begin
strTime:='';
if Length>=1000 then
begin
if (Length mod 1000)>=500 then
nTotalSeconds:= Length div 1000+ 1
else
nTotalSeconds:= Length div 1000;
nMinites:= nTotalSeconds div 60;
nSeconds:= nTotalSeconds- nMinites* 60;
if nMinites<10 then
strMinites:= '0'+IntToStr(nMinites)
else
strMinites:= IntToStr(nMinites);
if nSeconds<10 then
strSeconds:='0'+ IntToStr(nSeconds)
else
strSeconds:= IntToStr(nSeconds);
strTime:= strMinites+':'+ strSeconds;
end;
Result:= strTime;
end;
procedure TMP3Player.Timer2Timer(Sender: TObject);
var
strSec, strMin: String;
begin
if (LabelCurrent.Caption<>LabelTotal.Caption) and (MediaPlayer1.Mode= mpPlaying) then
begin
if nSec= 59 then
begin
nSec:=0;
nMin:= nMin+ 1;
end
else
nSec:= nSec+ 1;
if nSec<10 then
strSec:= '0'+IntToStr(nSec)
else
strSec:= IntToStr(nSec);
if nMin< 10 then
strMin:= '0'+IntToStr(nMin)
else
strMin:= IntToStr(nMin);
LabelCurrent.Caption:= strMin+':'+strSec;
end;
end;
procedure TMP3Player.Splitter1Moved(Sender: TObject);
begin
MediaPlayer1.Stop;
MediaPlayer1.StartPos:= EndPosition * Panel4.Width div Panel2.Width;
MediaPlayer1.Play;
LabelCurrent.Caption:= MilliSecondsToString(EndPosition * Panel4.Width div Panel2.Width);
nSec:= StrToInt(Copy(LabelCurrent.Caption,4,2));
nMin:= StrToInt(Copy(LabelCurrent.Caption,1,2));
end;
procedure TMP3Player.BtnRandomClick(Sender: TObject);
begin
if (N7.ImageIndex= 3) then
begin
//bRandom:= False;
BtnLoop.Enabled:= True;
BtnRandom.Glyph:= Nil;
ImageList1.GetBitmap(2,BtnRandom.Glyph);
BtnRandom.Hint:= '随机';
N7.Caption:= '随机';
N7.ImageIndex:= 2;
LabelRandom.Caption:= '随机';
end
else
begin
//bRandom:= True;
BtnLoop.Enabled:= False;
BtnRandom.Glyph:= Nil;
ImageList1.GetBitmap(3,BtnRandom.Glyph);
LabelRandom.Caption:= '顺序';
BtnRandom.Hint:= '顺序';
N7.Caption:= '顺序';
N7.ImageIndex:= 3;
end;
end;
procedure TMP3Player.BtnLoopClick(Sender: TObject);
begin
if bLoop then
begin
bLoop:= False;
BtnLoop.Glyph:= Nil;
ImageList1.GetBitmap(5,BtnLoop.Glyph);
BtnLoop.Hint:= '循环';
N8.Caption:= '循环';
N8.ImageIndex:= 3;
LabelLoop.Caption:= '循环';
end
else
begin
bLoop:= True;
BtnLoop.Glyph:= Nil;
ImageList1.GetBitmap(4,BtnLoop.Glyph);
LabelLoop.Caption:= '单次';
BtnLoop.Hint:= '单次';
N8.Caption:= '单次';
N8.ImageIndex:= 4;
end;
end;
procedure TMP3Player.FormCreate(Sender: TObject);
begin
DragAcceptFiles(Handle,True);
InstallIcon;
ShowWindow(Application.Handle,SW_HIDE);
//隐藏主窗体
SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);
//在切换状态栏上不显示程序图标
end;
procedure TMP3Player.DirListClick(Sender: TObject);
begin
DirList.Hint:=DirList.Items[DirList.ItemIndex];
end;
procedure TMP3Player.MusicListDragDrop(Sender, Source: TObject; X,
Y: Integer);
//var
//i: Integer;
begin
//if (Sender is TListBox) and (Source is TOpenDialog) then
//for i := 0 to MP3Open.Files.Count - 1 do
//begin
//DirList.Items.Add(MP3Open.Files[i]);
//MusicList.Items.Add(ExtractFileName(MP3Open.Files[i]));
//end;
//ON_WM_SYSCOMMAND
end;
procedure TMP3Player.MusicListDragOver(Sender, Source: TObject; X,
Y: Integer; State: TDragState; var Accept: Boolean);
//var
//i: Integer;
begin
//Accept:= True;
{if Source is TOpenDialog then
begin
Accept := True;
if (Sender is TListBox) and (Source is TOpenDialog) then
for i := 0 to MP3Open.Files.Count - 1 do
begin
DirList.Items.Add(MP3Open.Files[i]);
MusicList.Items.Add(ExtractFileName(MP3Open.Files[i]));
end;
end;}
end;
procedure TMP3Player.DragDropFiles(var msg: TMessage);
var
char1: array[0..128]of char; // 缓冲区
char2:pchar;
i,Sum:Integer;
strExe: String;
begin
try
// 获得拖拉的文件数目,该功能由第二个参数决定
sum:=DragQueryFile(msg.WParam,$FFFFFFFF,nil,0);
// 显示拖拉文件的数目
char2:=@char1;
for i:=0 to Sum-1 do
begin
// 获取第i 个拖拉文件的名字,并保存在缓冲区c h a r 2 中
DragQueryFile(msg.WParam,i,char2,128);
strExe:= LowerCase(ExtractFileExt(char2));
if ((strExe='.wmv')or(strExe= '.dat')or(strExe= '.mp3')or(strExe= '.wma')or(strExe= '.wma')or(strExe= '.wav')or(strExe= '.mid')) then
begin
DirList.Items.Add(char2);
MusicList.Items.Add(ExtractFileName(char2));
end;
end;
// 释放应用程序为传递文件名而开辟的内存空间
DragFinish(msg.WParam);
except
Exit;
end;
end;
procedure TMP3Player.MusicListClick(Sender: TObject);
begin
MusicList.Hint:= MusicList.Items[MusicList.ItemIndex];
end;
procedure TMP3Player.MusicListKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
nIndex: Integer;
begin
if Key= VK_Delete then
begin
for nIndex:= 0 to MusicList.Count -1 do
DirList.Selected[nIndex]:= MusicList.Selected[nIndex];
MusicList.DeleteSelected;
DirList.DeleteSelected;
end;
{if nIndex= MusicList.Count- 1 then
begin
MusicList.Items.Delete(nIndex);
DirList.Items.Delete(nIndex);
MusicList.ItemIndex:= MusicList.Count- 1;
end
else
begin
MusicList.Items.Delete(nIndex);
DirList.Items.Delete(nIndex);
MusicList.ItemIndex:= nIndex;
end;
end;
if (Key= VK_UP) and (nIndex> 0) then
MusicList.ItemIndex:= nIndex;
if (Key= VK_DOWN) and (nIndex< MusicList.Count- 1) then
MusicList.ItemIndex:= nIndex; }
end;
procedure TMP3Player.BtnSaveClick(Sender: TObject);
var
strInput: String;
ListFile: TextFile;
nIndex, nCount: Integer;
begin
nCount:= DirList.Count;
if nCount>0 then
begin
if (SaveDialog1.Execute) then
begin
AssignFile(ListFile,SaveDialog1.FileName);
Rewrite(ListFile);
Try
for nIndex:= 0 to nCount- 1 do
begin
strInput:= DirList.Items[nIndex];
Writeln(ListFile,strInput);
end;
Finally
CloseFile(ListFile);
end;
end;
end
else
MessageDlg('不能保存空列表!', mtInformation,[mbOk], 0);
end;
procedure TMP3Player.BtnListClick(Sender: TObject);
var
strInput: String;
ListFile: TextFile;
begin
MP3Open.Filter:= '列表文件(*.lst)|*.lst';
MP3Open.Options:= [ofHideReadOnly,ofEnableSizing];
if MP3Open.Execute then
begin
AssignFile(ListFile,MP3Open.FileName);
Reset(ListFile);
Try
DirList.Items.Clear;
MusicList.Items.Clear;
while not Eof(ListFile) do
begin
Readln(ListFile, strInput);
DirList.Items.Add(strInput);
MusicList.Items.Add(ExtractFileName(strInput));
end;
Finally
CloseFile(ListFile);
end;
MusicList.Selected[0]:=True;
MusicList.Selected[0]:=True;
end;
end;
procedure TMP3Player.IconOnClick(var message: TMessage);
var
Point: TPoint;
begin
if (message.LParam= WM_RBUTTONDOWN) then
begin
GetCursorPos(Point);
PopupMenu1.Popup(Point.X,Point.Y);
end
else
if (message.LParam= WM_LBUTTONDBLCLK) then
begin
MP3Player.Visible:= True;
//MP3Player.Show;
//Application.Minimize;
//ShowWindow(Handle,SW_HIDE);
end;
end;
procedure TMP3Player.InstallIcon;
begin
TrayIcon:= TIcon.Create;
TrayIcon.LoadFromFile('ani3.ico');
LittleIcon.cbSize:= sizeof(LittleIcon);
LittleIcon.Wnd:= Handle;
LittleIcon.uID:= ICON_ID;
LittleIcon.uFlags:= NIF_ICON or NIF_MESSAGE or NIF_TIP;
LittleIcon.uCallbackMessage:= MI_ICONEVENT;
LittleIcon.hIcon:= TrayIcon.Handle;
LittleIcon.szTip:= '播放器--- Allen 制造';
Shell_NotifyIcon(NIM_ADD,@LittleIcon);
end;
procedure TMP3Player.UnInstallIcon;
begin
Shell_NotifyIcon(NIM_DELETE,@LittleIcon);
end;
procedure TMP3Player.DealMessage(var message: TMessage);
begin
if (message.WParam= SC_MINIMIZE) then
begin
MP3Player.Visible:= False;
//Timer1.Enabled:= False;
//Timer2.Enabled:= False;
end
else
inherited;
end;
procedure TMP3Player.N1Click(Sender: TObject);
begin
BtnPlay.Click;
end;
procedure TMP3Player.N2Click(Sender: TObject);
begin
BtnStop.Click;
end;
procedure TMP3Player.N3Click(Sender: TObject);
begin
BtnPrevious.Click;
end;
procedure TMP3Player.N4Click(Sender: TObject);
begin
BtnNext.Click;
end;
procedure TMP3Player.N5Click(Sender: TObject);
begin
BtnStep.Click;
end;
procedure TMP3Player.N6Click(Sender: TObject);
begin
BtnBack.Click;
end;
procedure TMP3Player.N7Click(Sender: TObject);
begin
BtnRandom.Click;
end;
procedure TMP3Player.N8Click(Sender: TObject);
begin
BtnLoop.Click;
end;
procedure TMP3Player.N9Click(Sender: TObject);
begin
BtnList.Click;
end;
procedure TMP3Player.N10Click(Sender: TObject);
begin
BtnOpen.Click;
end;
procedure TMP3Player.N11Click(Sender: TObject);
begin
BtnSave.Click;
end;
procedure TMP3Player.N12Click(Sender: TObject);
begin
MP3Player.Close;
end;
procedure TMP3Player.BtnDelClick(Sender: TObject);
var
nIndex: Integer;
begin
for nIndex:= 0 to MusicList.Count -1 do
DirList.Selected[nIndex]:= MusicList.Selected[nIndex];
MusicList.DeleteSelected;
DirList.DeleteSelected;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -