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

📄 playlist.pas

📁 一个delphi制作的mp3播放器!
💻 PAS
📖 第 1 页 / 共 3 页
字号:
   LoadPath:string;
begin //注意此属性的巧用
     GDragLbNamLb:=False;
     ReNameed.Left:=LbName.Left;
     ReNameed.Height:=LbName.ItemHeight+40;//设置改名用的ReNameed的高度
     ReNameed.Width:=LbName.Width;
     dragacceptFiles(lbname.Handle,true);//接受拖动文件
     dragacceptFiles(MoreFilnameLb.Handle,true);//接受拖动文件
     PosSel:=-1;
     ComboBox1.itemIndex:=1;//默认选择'所有音乐';
     FilePath:=(ExtractFilePath(Application.ExeName));//应用程序的路径
     LoadPath:=FilePath+'playlist'; //优化代码
     if FileExists(loadpath+'\listName.pls')and FileExists(loadpath+'\listPath.pls')
        and FileExists(loadpath+'\MorelistName.pls') and FileExists(loadpath+'\MorelistPath.pls')then
          begin
               LbPath.Items.LoadFromFile(loadpath+'\listPath.pls');
               LbName.Items.LoadFromFile(loadpath+'\listName.pls');
               MoreFilNameLb.Items.LoadFromFile(loadpath+'\MorelistName.pls');
               MoreFilPathLb.Items.LoadFromFile(loadpath+'\Morelistpath.pls');
          end;
end;

procedure TForm3.LbNameDblClick(Sender: TObject);
begin
  if dragpos=LbName1 then  //取得鼠标的位置
     NameDbclick(LbName,LbPath)
  else
     NameDbclick(MoreFilNameLb,MoreFilPathLb);
end;

procedure NameClick(TName,TPath:Tlistbox); //自定义的单击过程
var
  CurrentIndex:word;
begin
   PosPlay:=-1;
   if TName.ItemIndex<>-1 then
      begin
         CurrentFile:=TPath.Items.Strings[TName.ItemIndex];//为按Enter键播放做准备
         Select:=True;
      end;
end;

procedure TForm3.MoreFilPathLbClick(Sender: TObject);
var
   Index:integer;
begin
    For Index:=0 to  MoreFilPathLb.Items.Count-1 do
    begin
       if MoreFilPathLb.Selected[Index] then
           currentFile:=MoreFilPathLb.Items.Strings[Index];
    end;
end;

procedure TForm3.KeyDown(LbNameKey,LbPathKey:Tlistbox;key:word;Shift:TShiftState);
var
   Sender: TObject;
begin
    OldIndex:=LbNamekey.ItemIndex;
   case Key of
    Vk_return://若回车,则播放
        begin
            currentFile:=LbPathkey.Items.Strings[OldIndex];
            if ReNameEd.Visible then
                  ReNameEdExit(Sender);
               Enter:=True;
               Form1.PlaySbtclick(Sender);
        end;
    Vk_space://播放/暂停切换
        Form1.PauseClick();
    Vk_Delete:
         DelSpb.Click;
    Vk_F2:
         ReNameClick(Sender);
   else
      Form2.FormKeyDown(sender,key,shift); //触发popumenu菜单项中的事件
    end;
end;

procedure TForm3.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
    Startx:=x;
    Starty:=y;
end;

procedure TForm3.LbNameMouseUp(Sender: TObject; Button: TMouseButton;
    Shift: TShiftState; X, Y: Integer);
var
  Dragx,Dragy:integer;
  PopMenu:TPopupMenu;
begin
try //Tlistbox(sender) 相当于 Sender as Tlistbox  and
    if Button<>mbLeft then Exit;
    MouDn:=False;
    {if not MouDn then
       Lbname.Cursor:=crDefault;}
     if DragPos=LbName1 then
       begin//私有变量保存(是正在播放的,还是所有音乐的列表)
          moveName:=LbName;
          MovePath:=LbPath;
       end
     else
        begin
          moveName:=MoreFilNameLb;
          MovePath:=MoreFilPathLb;
        end;
    NewIndex:=moveName.ItemAtPos(point(x,y),true);
    if (not moveName.MultiSelect) and (MouDnIndex<>NewIndex)
       and (NewIndex<>-1) then //若MouseDn与 MouseUp 的Item 相同则移动文件
        begin
           MoveName.Items.Move(MouDnIndex,NewIndex);//移动文件到NewIndex处
           MovePath.Items.Move(MouDnIndex,NewIndex);
           if MouDnIndex=Curpos then
              begin//如果是当前播放的一项, 则MouDnIndex的是正在播放的
                 Curpos:=NewIndex;
                 moveName.Selected[Curpos]:=True;
              end;
        end;
    if OldInd<>NewIndex then//ClickLb:=True 若两次的Item不同,则再记录
       begin
         if renameEd.visible  then
             renameEd.Hide; //ReNameEdExit(Sender);//若改名用的Edit未隐藏则隐藏
           OldInd:=MoveName.ItemAtPos(point(x,y),true);
       end
    Else
       if DbClick<>1 then //判断是否双击了LbName
             ReNameClick(Sender)//调用改名过程
       Else
          DbClick:=0;
Except
  Exit;
  end;
end;

procedure TForm3.ReNameClick(Sender: TObject);//自定义改名的事件
var
   LbItemRect:TRect;
begin
try
  LbItemRect:=moveName.ItemRect(OldInd);//得到 ItemIndex区域!
  ReNameed.Top:=moveName.Top+LbItemRect.top;//注意要加上播放列表的高度!
  ReNameed.Height:=LbName.ItemHeight+2;//设置改名用的ReNameed的高度
  if (moveName.ItemIndex<>-1) and (not FileFind(movePath.Items.Strings[moveName.ItemIndex]))then//判断文件是否存在
     exit;
  OldName:=movePath.Items.Strings[OldInd];
  ReNameed.Text:=moveName.Items.Strings[OldInd];//GetFileName(OldName);
  ReNameed.Show;
  ReNameed.SetFocus;
Except
  Exit;
  end;
end;

procedure TForm3.ReNameEdKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin //回车实现改名
   {if key=13 then
      ReNameEdexit(sender);}
end;

procedure TForm3.LbNameMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
    MouDnPos:=x;//记下鼠标按下时的位置
    MouDnIndex:=LbName.ItemAtPos(Point(x,y),True);
    MouDn:=True;
end;

procedure TForm3.LbNameDrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
var
  I:integer;
begin
try
    { if (index=nexpos) and (nexpos<>0) then //
        begin
          //lbName.Canvas.Pen.Color:=cllime;
          //lbName.Canvas.Brush.Color:=clgreen;
       end
     else
         begin
         if odSelected in state then
              begin
                  //lbName.Canvas.Pen.Color:=clwhite;
                  //lbName.Canvas.Brush.Color:=clblack;
              end
          else
             begin
                 //lbName.Canvas.Pen.Color:=clwhite;
                 //lbName.Canvas.Brush.Color:=clblack;
             end;
        end;
     for i:=0 to LbName.items.count-1 do
         begin
             rect:=lbName.ItemRect(i);
             lbName.Canvas.TextRect(rect,
                  1,i*lbName.ItemHeight,lbName.Items.Strings[i]);
         end;
      //caption:='index:'+IntTostr(index);//LbName.items.count-1); }
except
  exit;
  end;
end;

procedure TForm3.ReNameEdExit(Sender: TObject);
var
  EdAtIndex:Integer; // ReNameed所在的ItemIndex
  ReLbName,ReLbPath:Tlistbox;
begin
//try
   if DragPos=LbName1 then
       begin
          ReLbName:=LbName;
          ReLbPath:=Lbpath;
       end
   else
      begin
         ReLbName:=MoreFilNameLb;
         ReLbPath:=MoreFilPathLb;
      end;
   //ReLbName.Items.Strings[OldInd]:=ReNameed.Text;
   NewName:=ExtractFileDir(OldName)+'\'+
        ReNameEd.Text+ExtractFileExt(OldName);
   if (OldName=NewName) or (ReNameEd.Text='') then//若文件名没变或改为空,则不进行改名操作
      begin //要判断新文件名是否为空,即ReNameEd.Text='' 而不是NewName=''
          ReLbName.Items.Strings[OldInd]:=GetFileName(OldName);
          exit;
      end;
   if renameFile(OldName,NewName) then //调用改名函数
       begin
         ReLbPath.Items.Strings[OldInd]:=NewName;
         ReLbName.Items.Strings[OldInd]:=ReNameed.Text;//GetFileName(NewName);
       end
    Else
      begin
         //raise Exception.Create('文件重命名出错!');
         showmessage('文件重命名出错!');
      end;
    //ReNameed.Hide; //隐藏ReNameed showmessage
{except
   exit;
   end; }    
end;

procedure TForm3.ReNameEdChange(Sender: TObject);
begin
   // EdChange:=True;//判断是否改名
end;

procedure TForm3.ComboBox1Change(Sender: TObject);
begin  // 只有当用户改变它的text时才触发
  if ComboBox1.Text='正在播放' then
      begin
          MoreFilNameLb.Show;
          LbName.Hide;
          //Form1.Next(sender,MoreFilPathLb);//播放下一曲
      end;
  if  ComboBox1.Text='所有音乐' then
       begin
           LbName.Show;
           MoreFilNameLb.hide;
           //Form1.Next(sender,LbPath);
        end;
end;

procedure TForm3.Poperty1Click(Sender: TObject);
begin
     if DragPos=LbName1  then //判断鼠标位置 为枚举类型Form,LbName1,MoreFilNameLb1
          FileId3TagInformation(LbPath.Items.Strings[LbName.itemIndex]);
     if DragPos=MoreFilNameLb1 then
          FileId3TagInformation(MoreFilPathLb.Items.Strings[MoreFilNameLb.itemIndex]);
end;

procedure TForm3.MoreFilNameLbMouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
   ListboxName:=Tlistbox(sender);//根据文件列表是否有滚动条动态改变ReNameed的宽度
   if ListboxName=MoreFilNameLb then
      begin
         DragPos:=MoreFilNameLb1; //为获得鼠标的位置
         MoreFilLbMou.X:=x;//为获得鼠标所在的Item而取得位置
         MoreFilLbMou.Y:=y;
      end   
   else
      begin
         DragPos:=LbName1;
         LbNameMou:=point(x,y);
      end;   
   if ListboxName.ItemHeight*ListboxName.Count>ListboxName.Height then
      ReNameEd.Width:=ListboxName.Width-22
   else
      ReNameEd.Width:=ListboxName.Width;
end;

procedure TForm3.MoreFilNameLbExit(Sender: TObject);
begin
    GDragMorFilLb:=False;
end;

procedure TForm3.LbNameExit(Sender: TObject);
begin
    GDragLbNamLb:=False;
end;

procedure TForm3.MoreFilNameLbClick(Sender: TObject);
begin
    NameClick(MoreFilNameLb,MoreFilPathLb);

⌨️ 快捷键说明

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