⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.pas

📁 一个delphi制作的mp3播放器!
💻 PAS
📖 第 1 页 / 共 3 页
字号:
             else
                showmessage('"正在播放" 列表中无文件!');
           Exit;//若列表中无文件则退出!
          end;
 if pos(TSpeedbutton(sender).Name,'PrePreP')<>0 then//若是下一曲
     begin
       if ((Curpos>0) and (Curpos<=NexLb.Items.Count-1)) then
             Curpos:=Curpos-1
           Else
             Curpos:=NexLb.Items.Count-1;//从最后面开始
      end
 else
     begin
        if ((Curpos>=0) and (Curpos<NexLb.Items.Count-1)) then
             Curpos:=Curpos+1
           Else
             Curpos:=0;
     end;
   currentFile:=NexLb.Items.Strings[Curpos];
   //PlaySbtClick(sender);
   //Label1.caption:=TSpeedbutton(sender).Name;
   if not FileExists(currentFile) then//若文件没找到,自动跳到下一曲
       Form1.Next(sender,NexLb);
   with Form1 do
      begin
           MediaPlayer1.FileName:=currentFile;
           MediaPlayer1.Open;
           mediaPlayer1.Play;
           Form1.Lbrun.Visible:=True;
           LbRunTimer.Enabled:=True;
           Lbrun.Caption:=ExtractFileName(currentFile);
           Form2.Caption:=ExtractFileName(currentFile);
           Picture1(MediaPlayer1.FileName);
           PlayInf(CurrentFile);//显示文件信息
           Form3.LbName.Selected[Curpos]:=true;
       end;
except
  exit;
  end;
end;

Function FileFind(FileName:string):boolean;
begin
     if not FIleExists(FileName) then
          begin
              showmessage(FileName+'未找到!');
              result:=False;
          end
     Else
         result:=True;
 end;

procedure TForm1.DragFilePic(var MessDrop:Tmessage);
begin
    inherited;
   if messDrop.Msg=Wm_dropFiles  then
      Form3.WmDragFile(messDrop);//调用拖动文件添加处理
end;

procedure TForm1.FormCreate(Sender: TObject);
var
   count,i,pos:integer;
   Zappname:array[0..127] of char;
   Hold1:pchar;
   Hold:string;
   Found:Hwnd;
   ReadVol:longInt;
begin
    picture.Apply;
    Hold:=Application.Title;
    Application.showhint:=true;
    DotIm.Left:=BarIm.Left;
    VolIncIm.Left:=MaxVolIm.Left;//初始化调音量图标的位置
    VolIncIm.top:=MaxVolIm.top;
    dragacceptFiles(Form1.handle,true);//接受拖动文件
    AutoStart:=0;
    Auto:=False;
    Again:=False;
   count:=auxGetNumDevs;
   candrag:=False;
   doorOpen:=False;//标识光驱关闭
   Frame:=10;// 初始步进值为10
   //该函数改变指定窗口的属性。GWL_ExSTYLE
   //函数也将在指定偏移地址的一个32位值存入窗口的额外窗口存,如Ws_Ex_toolwindow(384)
   for i:=0 to Count do
      begin
        auxgetVolume(I,addr(vol[i]));
    end;
end;

procedure TForm1.LbRunTimerTimer(Sender: TObject);
begin
try
    DotTim.Enabled:=true;
    Freq:=round(Mediaplayer1.Length/(barIm.Width-dotIm.Width));
    if  LbRun.Left>=ImageFrom.Left then
          LbRun.Left:=LbRun.Left-1
     Else
          LbRun.left:=ImageFrom.Left+ImageFrom.Width;
     if mediaplayer1.Position=mediaplayer1.Length then//播放停止
         begin
             Lbrun.Visible:=False;
             AutoTimer.Enabled:=true;//设置自动播放下一曲
         end;
      DotImPos:=0;
      Application.title:='渐美播放器: 当前播放 '+Mediaplayer1.filename;
except
  Exit;
end;
 end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
   FilePath:=ExtractFilepath(Application.ExeName)+'playlist\';
    if (FileFind(FilePath+'listName.pls')
       and FileFind(FilePath+'listpath.pls'))  then
       begin
           Form3.LbName.Items.SaveToFile(FilePath+'listName.pls');
           Form3.LbPath.Items.SaveToFile(Filepath+'listpath.pls');
       end; //若文件不存在则自动创建 MorelistName.pls,但不会创建文件夹playlist
    if (FileFind(FilePath+'MorelistName.pls')
       and FileFind(FilePath+'MorelistPath.pls'))  then
       begin
           Form3.MoreFilNameLb.Items.SaveToFile(FilePath+'MorelistName.pls');
           Form3.MoreFilPathLb.Items.SaveToFile(Filepath+'MorelistPath.pls');
       end;
end;
procedure TForm1.PauseClick();//处理暂停事件
begin
    if MediaPlayer1.DeviceID<>0 then //表示已打开文件
       begin //若停止则播放
         if MediaPlayer1.Mode=mpstopped then
         begin
            MediaPlayer1.Play;//设置右键 暂停  未选中
            PlayOrPau.Checked:=False;
         end
         Else//如果正在播放或暂停
            MediaPlayer1.Pause;//设置右键 暂停  选中
        if MediaPlayer1.Mode=mppaused then
           begin
              Label1.caption:='暂停'; //显示暂停标志
              PlayOrPau.Checked:=true;
              PauseSign.Visible:=true;
           end
        else //若是播放
           begin
              PlayOrPau.Checked:=false;
              PauseSign.Visible:=false;//隐藏暂停标志
           end;
        LbRunTimer.Enabled:=not PauseSign.Visible;
       end;
end;

procedure TForm1.PauseSignClick(Sender: TObject);
begin
    PauseClick();
end;

procedure TForm1.FormNoralClick(Sender: TObject);
begin
    close;
end;

procedure TForm1.ScreenClick(Sender: TObject);
begin
    if Form5.Visible then
        begin
           Form5.hide;
           HideVideo.checked:=true;
           exit;//注意要加上这条语句
        end;
    if Form2.Visible then
       begin
         Form2.hide;
         HideVideo.checked:=true;
         exit;
        end;
    if not (Form2.Visible or Form2.Visible) then//两个窗体都隐藏了
      begin
        Form2.Show;
        HideVideo.checked:=false;
      end;  
end;

procedure TForm1.FormExitClick(Sender: TObject);
begin
    close;
end;

procedure TForm1.AgainTimerTimer(Sender: TObject);
begin
   if mediaplayer1.Position=mediaplayer1.Length then
         begin
              MediaPlayer1.Play;
              Lbrun.Visible:=True;
         end;
end;

procedure TForm1.DoAgainClick(Sender: TObject);//处理重复播放
var
  PicPath:string;
begin
try
   if MediaPlayer1.Mode=Mpseeking then Exit;//如果文件未打开则退出
   if ((MediaPlayer1.Mode=Mpplaying)or( mediaplayer1.Position=MediaPlayer1.Length)) then
     begin
        if Auto=True then
            Form1.AutoPlayClick(Sender);
        AgainTimer.Enabled:=not AgainTimer.Enabled;
        PicPath:=ExtractFilePath(Application.ExeName)+'skin\';
         if  AgainTimer.Enabled then
           begin //显示重复播放信息
                if  FileFind(PicPath+'barWediaNew.bmp') then
                      barIm.Picture.LoadFromFile(PicPath+'barWediaNew.bmp');
                AgainPlay.Checked:=true;//设置右键 重复  选中
            end
         else //不显示重复播放信息
           begin
             if FileFind(PicPath+'barWindow.bmp') then
                   barIm.Picture.LoadFromFile(PicPath+'barWindow.bmp');
             AgainPlay.Checked:=false;//设置右键 重复  未选中
           end;
        DoagainPicture.Visible:=not DoagainPicture.Visible;
        AgainSign.Visible:= not AgainSign.Visible;
        Again:=True;
    end;
Except
  Exit;
 end;  
end;

procedure TForm1.DoagainPictureClick(Sender: TObject);
begin
     DoAgainClick(Sender);
end;

procedure TForm1.NexClick(Sender: TObject);//播放下一曲
begin
   PreClk:=true;
   if Form3.combobox1.itemIndex=0 then//当 "正在播放"的列表
       Next(sender,Form3.MoreFilPathLb)//播放下一曲
    else
       Next(sender,Form3.Lbpath);
  end;

procedure TForm1.AutoPlayClick(Sender: TObject);
begin
    if Again=True then
          Form1.DoAgainClick(Sender);
    AutoTimer.Enabled:=not AutoTimer.Enabled;
         if AgainSign.Visible=false then
               AgainSign.Visible:=True
          Else
               AgainSign.Visible:=False;
         if AgainSign.Caption<>'自动' then
             begin
               AgainSign.Caption:='自动';
               Auto:=True;
             end;  
end;

procedure TForm1.ShowTimeTimer(Sender: TObject); //显示时间 
begin
   Enter:=False;
  if Mediaplayer1.Mode=Mpplaying then
   begin
       Label1.Visible:=True;
       SourceLen:=Time(MediaPlayer1.Length);
       CurrentLen:=Time(MediaPlayer1.Position);
       Label1.Caption:=SourceLen+'/'+Currentlen;
       Form2.Caption:=(Mediaplayer1.FileName)+'<'+Label1.Caption+'>';
   end;
end;

procedure TForm1.AutoTimerTimer(Sender: TObject);
begin
   if (Mediaplayer1.Mode=mpstopped)  then
      begin  //判断是否播放完! 注意 Mode此属性的巧用
         if AutoStart=0 then
          NexClick(Sender);
          DoAgain.Enabled:=not DoAgain.Enabled;
          LbRun.Visible:=True;
          ShowTime.Enabled:=True;
      end;
end;

procedure TForm1.StepImClick(Sender: TObject);
begin
try
   With Mediaplayer1 do
     begin
        if ((mode in [mpplaying,mpstopped]) and (Position<>Length)) then
            begin //正在播放或停止 
               Pause;
               Position:=Position+round(Frame*1000);//没有初始步进值,故快进无效
               Play;
            end;
     end;
Except
  Exit;
 end;
end;

procedure TForm1.BackImClick(Sender: TObject);
begin
     With Mediaplayer1 do
     begin              
        if (mode in [mpplaying,mpstopped]) then
            begin
               Pause;
               Position:=Position-round(Frame*1000);
               Play;
            end;
     end;
end;
procedure TForm1.OPCDDoorDblClick(Sender: TObject);//打开关闭CDROM
begin
   if doorOpen=false then
     begin
       if Mcisendstring('Set cdaudio door open',nil,0,handle)=0 then
          begin
             doorOpen:=true;
             OPCDDoor.hint:='打开';
          end
       else
          showmessage('打开CDROM失败!');
     end
     Else
     begin
        if Mcisendstring('Set cdaudio door closed',nil,0,handle)=0 then
           begin
               dooropen:=False;
               OPCDDoor.hint:='关闭';
           end
        else
           showmessage('关闭CDROM失败!');
     end;
end;

procedure TForm1.StepPopClick(Sender: TObject);//快进播放
begin
     StepImclick(Sender);
end;

procedure TForm1.BackPopClick(Sender: TObject);//后退播放
begin
     backImclick(Sender);
end;

procedure TForm1.Ctrle1Click(Sender: TObject);
begin
    StopSdbClick(Sender);
end;

procedure TForm1.PictureMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
  MousePos:Tpoint;
  messmove:Tmessage;
begin
   Picx:=x;
   PicY:=y;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -