{$R *.dfm} //记算时间 function showtime(x:integer):string; var h,m:integer; begin h:=0; m:=0;
x:=x div 1000; if x>3600 then begin h:=x div 3600; x:=x-h*3600; end; if x>60 then begin m:=x div 60; x:=x-m*60; end;
showtime:=inttostr(h)+':'+inttostr(m)+':'+inttostr(x); end; //获取托放文件 procedure TNPx.WMDropFiles(var message:TMessage); var P:array[0..254] of char; I:word; begin Inherited;
{$IFDEF WIN32} I:=DragQueryFile(Message.wParam,$ffffffff,nil,0); {$ELSE} I:=DragQueryFile(Message.wParam,$ffff,nil,0); {$ENDIF} for I:=0 to I-1 do begin DragQueryFile(Message.WParam,I,P,255); NPmusic_list.Items.Add(StrPas(p)); NPmusic_list2.Items.Add(ExtractFileName(StrPas(p))); end; end; //退出 procedure TNPX.PexitClick(Sender: TObject); begin close; end; //显示列表 procedure TNPX.PlistClick(Sender: TObject); begin if NPmusic_list2.Visible=true then NPmusic_list2.Hide else NPmusic_list2.Show; end;
procedure TNPX.FormCreate(Sender: TObject); var SoundPostion: Longint; begin //获取文件 DragAcceptFiles(NPx.Handle,True); //取当前音量状态发给音量控制 Smove:=false; WaveOutGetVolume(0, @SoundPostion);
NPtime.Enabled:=false; MP.Notify:=true; pl:=false; ploop:=true; setp:=1; mydir:=ExtractFileDir(application.ExeName); if copy(mydir,Length(mydir), 1)<>' then mydir:=mydir+'; //有执行参数传入 if ParamCount > 0 then begin NPmusic_list.Items.Clear; NPmusic_list.Items.Add(ParamStr(1)); NPmusic_list2.Items.Clear; NPmusic_list2.Items.Add(ExtractFileName(ParamStr(1))); p:=0; NPmusic_title.Caption:=ExtractFileName(ParamStr(1)); NPtime.Enabled :=true; end; end; //窗体移动 procedure TNPX.mainboxMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin if moves=true then begin NPx.Left:=NPx.Left+X-mX; NPx.Top:=NPx.Top+Y-mY; end; end;
procedure TNPX.mainboxMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if moves=false then begin moves:=true; mx:=X; my:=Y; end; end;
procedure TNPX.mainboxMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if moves=true then moves:=false; end; //窗体移动结束 //调整音量 procedure TNPX.NPsound_sMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin if Smove=true then NPsound_s.Left:=NPsound_s.Left+X-sX; if NPsound_s.Left>157 then NPsound_s.Left:=157; if NPsound_s.Left<112 then NPsound_s.Left:=112; end;
procedure TNPX.NPsound_sMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if Smove=false then begin Smove:=true; mx:=X; NPtime1.Enabled:=false; end; end;
procedure TNPX.NPsound_sMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var ProBarVal, SoundVal: longint; begin NPtime1.Enabled:=true; if Smove=true then begin Smove:=false; ProBarVal := Round((NPsound_s.left-112)/45*255); SoundVal := (ProBarVal shl 8) or (ProBarVal shl 24); waveoutsetvolume(0, SoundVal); end; end; //调整音量结束 //自动隐身 procedure TNPx.NPtime1Timer(Sender: TObject); var tpos:TPoint; T:bool; SoundPostion: Longint; begin //info.Caption:=datetimetostr(now); //取当前音量状态发给音量控制 WaveOutGetVolume(0, @SoundPostion); NPsound_s.Left:=112+Round(Hi(SoundPostion)/255*45); if (NPx.top>=MY_Height) and (NPx.top<5) then begin T:=true; end else begin T:=false; end; if T=true then begin GetCursorPos(tpos); if (tpos.X>NPx.Left) and (tpos.X<(NPx.Left+NPx.Width)) and (tpos.Y>NPx.Top) and (tpos.Y<(NPx.Top+NPx.Height+10)) then begin NPx.Top:=0; //让本窗体始终位于所有窗体之上 setWindowPos(Application.Handle,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE or SWP_NOSIZE); end else begin NPx.Top:=MY_Height; end; end; end; //播放过程 procedure TNPX.Nplay; begin MP.Close; MP.FileName:=NPmusic_list.Items.Strings[p]; try MP.Open; MP.Play; pl:=true; except MP.Close; NPtime.Enabled:=false; showmessage('有错误,媒体格式不对或路径不对'); end; NPmusic_list2.ItemIndex:=p; NPmusic_title.Caption :=ExtractFileName(MP.FileName); application.Title:='诺克播放器v0.28TIGER->'+NPmusic_title.Caption; NPmusic_title.Hint:=MP.FileName; end; //列表单击播放 procedure TNPX.NPmusic_list2Click(Sender: TObject); begin p:=NPmusic_list2.ItemIndex; NPtime.Enabled :=true; Nplay; end; //验证播放器 procedure TNPX.MPNotify(Sender: TObject); begin if MP.NotifyValue=nvSuccessful then begin NPmusic_time.Caption:=showtime(MP.Position)+'/'+showtime(MP.Length); end; MP.Notify:=true; end; //设置进度 procedure TNPX.NPprogressMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin if Smove=true then NPprogress.Left:=NPprogress.Left+X-sX; if NPprogress.Left>248 then NPprogress.Left:=248; if NPprogress.Left<16 then NPprogress.Left:=16; end;
procedure TNPX.NPprogressMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if Smove=false then begin Smove:=true; mx:=X; NPtime.Enabled :=false; end; end;
procedure TNPX.NPprogressMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if Smove=true then begin Smove:=false; if pl then begin MP.Position:=Round((NPprogress.Left-16)/232*MP.Length); NPtime.Enabled :=true; MP.Play; end; end; end; //设置进度结束 //进度 procedure TNPX.NPtimeTimer(Sender: TObject); begin if pl=false then begin if p<=NPmusic_list.Items.Count-1 then begin Nplay; end else begin p:=0; NPtime.Enabled:=false; NPmusic_time.Caption:=showtime(MP.Position)+'/'+showtime(MP.Length); end; end else begin NPmusic_time.Caption:=showtime(MP.Position)+'/'+showtime(MP.Length);
if MP.Position=MP.Length then begin p:=p+setp; setp:=1; if p<0 then p:=0; if (ploop=true) and (p>NPmusic_list.Items.Count-1) then p:=0; pl:=false; NPmusic_list2.ItemIndex:=p; end; end;
end; //上一曲 procedure TNPX.PupClick(Sender: TObject); begin if pl=true then begin p:=p-1; if p<0 then P:=NPmusic_list.Items.Count-1; NPtime.Enabled :=true; Nplay; end; end; //下一曲 procedure TNPX.PdownClick(Sender: TObject); begin if pl=true then begin p:=p+1; if p>NPmusic_list.Items.Count-1 then P:=0; NPtime.Enabled :=true; Nplay; end; end; //播放 procedure TNPX.PplayClick(Sender: TObject); begin if pl=true then MP.Play; NPtime.Enabled :=true; end; //暂停 procedure TNPX.PpauseClick(Sender: TObject); begin if NPtime.Enabled=true then begin MP.Pause; NPtime.Enabled :=false; end; end; //停止 procedure TNPX.PstopClick(Sender: TObject); begin if NPtime.Enabled=true then begin MP.stop; NPtime.Enabled :=false; end; end; //打开 procedure TNPX.PopenClick(Sender: TObject); var i:integer; begin
if(OD.Execute()) then begin NPmusic_list.Items:=OD.Files; NPmusic_list2.Items.clear; for I:=0 to NPmusic_list.Count-1 do begin NPmusic_list2.Items.Add(ExtractFileName(NPmusic_list.Items.Strings[i])); end; p:=0;
end; end; //最小化 procedure TNPX.PminiClick(Sender: TObject); begin application.Minimize; end; // 版权信息 procedure TNPX.PaboutClick(Sender: TObject); begin MessageBox(Handle, '诺克媒体播放器v0.28'+#13+'作者:王德超'+#13+ '2001.05 v0.1 VB 单曲播放 for win9x'+#13+ '2001.06.14 v0.2 BCB4 播放列表、皮肤等 for win9x/winXp'+#13+ '2001.09.20 v0.201b4 键盘控制、文件拖放等 for win9x/winXp'+#13+ '2003.02.02 v0.25复活版 delphi7 重塑代码 for win9x'+#13+ '2003.07.19 v0.26 广播、下载 for win9x'+#13+ '2003.10.05 v0.27XP 自动隐身 for win9x/winXP'+#13+ '2004.01.01 v0.28TIGER for win9x/winXP', '版权信息', MB_ICONINFORMATION + MB_OK); end;
procedure TNPX.NploopClick(Sender: TObject); begin if ploop=true then begin ploop:=false;
nPloop.hint:='当前循环状态:否'; end else begin ploop:=true;
nploop.hint:='当前循环状态:是'; end;
end;
procedure TNPX.clearFilelistClick(Sender: TObject); begin NPmusic_list.Items.Clear; NPmusic_list2.Items.Clear; end;