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

📄 main.pas

📁 delphi2007写的播放器源码。效果类似于千千静听。
💻 PAS
📖 第 1 页 / 共 3 页
字号:
procedure TForm1.imgV_BarPositionMouseLeave(Sender: TObject);
begin
  painting(imgV_BarPosition,coninfo,1);
end;

procedure TForm1.imgV_BarPositionMouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
var
  myPos:integer;
begin
  painting(imgV_BarPosition,coninfo,0);

  if Shift=[ssleft] then
  begin
    myPos:=imgV_BarPosition.Left+(X-VolumePos.X);
    if (myPos<=imgV_Ntrack.Left) then
       imgV_BarPosition.Left:=imgV_Ntrack.Left
    else if (myPos>=imgV_Ntrack.Left+imgV_Ntrack.Width) then
       myPos:=imgV_Ntrack.Left+imgV_Ntrack.Width
    else if ((myPos>imgV_Ntrack.Left)and(myPos<imgV_Ntrack.Left+imgV_Ntrack.Width))then
      imgV_BarPosition.Left:=myPos;
    imgV_track.Width:=abs(imgV_Ntrack.Left-imgV_BarPosition.Left);
  end;
  //设置音量
  NowVolume:=abs(imgV_BarPosition.Left-imgV_ntrack.Left)/imgV_ntrack.Width;
  BASS_ChannelSetAttribute(chan, BASS_ATTRIB_VOL, NowVolume);
end;

function TForm1.PanleInitialization:boolean;
var
  I:integer;
begin
  Result:=true;

  LoadTitleConfig;
  setLength(ConInfo,ControlCount);

  for I := 0 to ControlCount - 1 do
    if Controls[I] is TImage then
      TImage(Controls[I]).Picture.Assign(nil);

  if not FaceInitialization(self,path+skinpath+'config.ini',ConInfo) then
  begin
    Result:=False;
    Exit;
  end;

  self.Width:=imgpanel.Width;
  self.Height:=imgpanel.Height;

  if FileExists(path+skinpath+ico) then
  begin
    application.Icon.LoadFromFile(path+skinpath+ico);
    self.Icon.LoadFromFile(path+skinpath+ico);
  end;
  LoadTitle(imgpanel,maintitle);
  LoadTitle(imgTagTitle,TagTitle);
  self.TransparentColor:=tran;
  self.TransparentColorValue:=backcolor;
  imgG_ntrack.Width:=G_length;
  play:=coninfo[imgplay.tag].image;
  imgNowTime.Width:=imgNowTime.Width*5;

  if isplay then
  begin
    coninfo[imgplay.Tag].Image:=pause;
    painting(imgplay,coninfo,0);
    Time_G_Bar:= Trunc((FullTime * 1000)/G_length);
    Timer1.Interval:=Time_G_Bar;
    imgG_BarPosition.Left:=imgG_Ntrack.Left+trunc((NowTime*1000)/Time_G_Bar);
    imgG_track.Width:=abs(imgG_Ntrack.Left-imgG_BarPosition.Left);
  end
  else if isPause then
  begin
    ShowTime;
    Time_G_Bar:= Trunc((FullTime * 1000)/G_length);
    Timer1.Interval:=Time_G_Bar;
    imgG_BarPosition.Left:=imgG_Ntrack.Left+trunc((NowTime*1000)/Time_G_Bar);
    imgG_track.Width:=abs(imgG_Ntrack.Left-imgG_BarPosition.Left);
  end
  else
  begin
    ResetTime;
  end;
  imgG_track.Width:=abs(imgG_Ntrack.Left-imgG_BarPosition.Left);
  imgV_ntrack.Width:=V_length;
  imgV_BarPosition.Left:=imgV_ntrack.Left+trunc(NowVolume*imgV_ntrack.Width);
  imgV_track.Width:=abs(imgV_Ntrack.Left-imgV_BarPosition.Left);



  BackImage.Visible:=paintframe.Visible;
  BackImage.Top:=paintframe.Top;
  BackImage.Left:=paintframe.Left;
  BackImage.Width:=paintframe.Width;
  BackImage.Height:=paintframe.Height;

  painting(imgCapture,coninfo,1);

  //圆形初始化
  CircleScope := TCircleScope.Create(PaintFrame.Width, PaintFrame.Height);
  //矩形初始化
  OcilloScope := TOcilloScope.Create(PaintFrame.Width, PaintFrame.Height);
  //波浪形初始化
  Spectrum    := TSpectrum.Create(PaintFrame.Width, PaintFrame.Height);
  
  update;
end;

function TForm1.ShowFormat(Second:Double):string;
var
  temp,Index:integer;
  bmpMiddle:TBitmap;
begin
  bmpMiddle:=TBitmap.Create;
  bmpMiddle.Width:=imgNowTime.Width;
  bmpMiddle.Height:=imgNowTime.Height;

  temp:=trunc(Second) div 60;//分钟
  temp:=temp mod 60; //小时

  Index:=temp div 10; //十分位
  Result:=inttostr(Index);
  burshTime(bmpMiddle,trunc(imgNowTime.Width/5),imgNowTime.Height,Index,0);

  Index:=temp mod 10; //个分位
  Result:=Result+inttostr(Index)+':';
  burshTime(bmpMiddle,trunc(imgNowTime.Width/5),imgNowTime.Height,Index,1);

  Index:=10;    //':'
  burshTime(bmpMiddle,trunc(imgNowTime.Width/5),imgNowTime.Height,Index,2);
  //----------------------------------------------------------
  temp:=trunc(Second) mod 60; //秒

  Index:=temp div 10;  //十分位
  Result:=Result+inttostr(Index);
  burshTime(bmpMiddle,trunc(imgNowTime.Width/5),imgNowTime.Height,Index,3);

  Index:=temp mod 10; //个分位
  Result:=Result+inttostr(Index);
  burshTime(bmpMiddle,trunc(imgNowTime.Width/5),imgNowTime.Height,Index,4);

  imgNowTime.Picture:=nil;
  bitblt(imgNowTime.Canvas.Handle,0,0,imgNowTime.Width,
      imgNowTime.Height,bmpMiddle.Canvas.Handle,0,0,SRCCOPY);

  bmpMiddle.Free;
  imgNowTime.Refresh;
end;
procedure TForm1.ShowTime;
var
  strs:string;temp,temp2:integer;
begin
  //当前时间
  NowTime:=round(BASS_ChannelBytes2Seconds(chan, BASS_ChannelGetPosition(chan, BASS_POS_BYTE)));
  strs:=ShowFormat(NowTime);
  strs:=strs+'/';

  temp:=trunc(FullTime) div 60;//分
  temp:=temp mod 60;//小时

  temp2:=temp div 10;
  strs:=strs+inttostr(temp2);
  temp2:=temp mod 10;
  strs:=strs+inttostr(temp2)+':';
  temp:=trunc(FullTime) mod 60; //秒
  temp2:=temp div 10;
  strs:=strs+inttostr(temp2);
  temp2:=temp mod 10;
  strs:=strs+inttostr(temp2);

  lbltime.Caption:=strs;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  //当前播放状态
  if not IsPlay then
  begin
    StopPlay;
    timer1.Enabled:=false;
    if ReplaceFile then  playfile;
  end
  else
  begin
    imgG_barposition.Left:=imgG_barposition.Left+1;
    imgG_track.Width:=abs(imgG_BarPosition.Left-imgG_ntrack.Left);
  end;
end;

procedure TForm1.Timer2Timer(Sender: TObject);
begin
  if not IsPlay then
  begin
    Timer2.Enabled:=false;
    Exit;
  end;
  ShowTime;
end;

procedure  RefreshTitle(temp:TImage;temp2:TTitle;X,Y:integer);
begin
  temp.Canvas.Font.Color:=temp2.Color;
  temp.Canvas.Font.Height:=temp2.Height;
  temp.Canvas.Font.Name:=temp2.facename;
  temp.Canvas.Font.Size:=temp2.Size;
  temp.Canvas.Brush.Style:=bsClear;
  temp.Canvas.TextOut(X,Y,temp2.caption);
  temp.Refresh;
end;

procedure TForm1.Timer3Timer(Sender: TObject);
var
  W,TW:integer; //X 输出坐标 W 控件宽度 TW 输出字符串宽度
begin
  imgTagTitle.Picture.Assign(nil);
  W:=imgTagTitle.Width;
  TW:=imgTagTitle.Canvas.TextWidth(TagTitle.caption);

  if (TX+TW)<0 then TX:=W;
  Dec(TX);
  RefreshTitle(imgTagTitle,TagTitle,TX,1);
  
end;

procedure TForm1.TimerRenderTimer(Sender: TObject);
var
  FFTFata : TFFTData; WaveData  : TWaveData;
  PaintTemp:TPaintBox;
begin
  case  IsWindowVisible(form4.Handle)  of
    false:
    begin
      PaintTemp:=PaintFrame;
    end
    else
    begin
      PaintTemp:=form4.PaintFrame;
    end;
  end;
  case BASS_ChannelIsActive(chan) of
   BASS_ACTIVE_STOPPED:
   begin
     isPlay:=False;
   end;
   BASS_ACTIVE_PLAYING:
   begin
     isPlay:=True;
   end;
   BASS_ACTIVE_PAUSED:
   begin
     isPause:=True;
   end;
   BASS_ACTIVE_STALLED:
   begin
     //
   end; 
  end;


  if not IsPlay then
  begin
    TimerRender.Enabled:=false;
    Exit;
  end;

  TrackPeak;
  ShowTime;

  case form4.RadioDraw.ItemIndex of
  0 :
   begin //圆形选择
    BASS_ChannelGetData(chan, @WaveData, 2048);
    CircleScope.Draw (PaintTemp.Canvas.Handle, WaveData
        , form4.TrackX.Position, form4.TrackY.Position);
   end;

  1 :
   begin //波浪形选择
    BASS_ChannelGetData(chan, @WaveData, 2048);
    OcilloScope.Draw (PaintTemp.Canvas.Handle, WaveData
        , form4.TrackX.Position - 50, form4.TrackY.Position);
   end;

  2 :
   begin //矩形选择
    BASS_ChannelGetData(chan, @FFTFata, BASS_DATA_FFT1024);
    Spectrum.Draw (PaintTemp.Canvas.Handle, FFTFata
        , form4.TrackX.Position - 40, form4.TrackY.Position - 60);
   end;
  end;
end;

procedure TForm1.burshTime(bmpTemp:TBitmap;X,Y:integer;Index,Num:integer);
var
bmp:TBitMap;
begin
  if not(FileExists(path+skinPath+ConInfo[imgNowTime.Tag].Image)) then Exit;
  bmp:=TBitmap.Create;

  bmp.LoadFromFile(path+skinPath+ConInfo[imgNowTime.Tag].Image);
  bitblt(bmpTemp.Canvas.Handle,X*Num,0,X,
      Y,bmp.Canvas.Handle,X*Index,0,SRCCOPY);
  bmp.Free;
end;
procedure Tform1.ResetTime;
var
  bmpMiddle:TBitmap;
begin
  bmpMiddle:=TBitmap.Create;
  bmpMiddle.Width:=imgNowTime.Width;
  bmpMiddle.Height:=imgNowTime.Height;

  burshTime(bmpMiddle,trunc(imgNowTime.Width/5),imgNowTime.Height,0,0);
  burshTime(bmpMiddle,trunc(imgNowTime.Width/5),imgNowTime.Height,0,1);
  burshTime(bmpMiddle,trunc(imgNowTime.Width/5),imgNowTime.Height,10,2);
  burshTime(bmpMiddle,trunc(imgNowTime.Width/5),imgNowTime.Height,0,3);
  burshTime(bmpMiddle,trunc(imgNowTime.Width/5),imgNowTime.Height,0,4);

  imgNowTime.Picture:=nil;
  bitblt(imgNowTime.Canvas.Handle,0,0,imgNowTime.Width,
      imgNowTime.Height,bmpMiddle.Canvas.Handle,0,0,SRCCOPY);

  bmpMiddle.Free;
  imgNowTime.Refresh;
end;

procedure TForm1.LoadSkinList(Sender: TObject);
var
  aitem:TMenuItem;
  I:integer;
begin
  SkinList:=TStringList.Create;
  templist:=TstringList.Create;

  DirToSkins(path+'skins',false);
  for I := 0 to templist.Count - 1 do
  begin
    aitem:=tmenuitem.Create(self);
    aitem.Caption:=templist[I];
    aitem.OnClick:=LoadSkin;
    aitem.Name:='skin'+inttostr(I);
    if ('skins\'+aitem.Caption+'\')=skinpath then
       aitem.Checked:=true;

    NskinMenu.Add(aitem);
  end;

  templist.Free;
end;

procedure TForm1.N10Click(Sender: TObject);
begin
  form5.Show;
end;

procedure TForm1.NrenewClick(Sender: TObject);
begin
  if not(IsWindowVisible(handle)) then
  begin
    Nrenew.Checked:=true;
    ShowWindow(Handle, SW_SHOW);
    if IsShowList then ShowWindow(form2.Handle, SW_SHOW);
    IcoDestroy;
  end;
end;

procedure TForm1.LoadSkin(Sender: TObject);
var
  I:integer;
  temp:string;
begin
  if AnsiContainsText(skinpath,'skins\'+TMenuItem(Sender).Caption+'\') then  Exit;
  
  //更换皮肤
  temp:=skinpath;
  skinpath:='skins\'+TMenuItem(Sender).Caption+'\';

 if not(PanleInitialization) or not(form2.PanleInitialization) then
  begin
    skinpath:=temp;
    //form4.SetBackImage;
    Exit;
  end;

  UniteTag;
  form4.LoadConfig;

  for I := 0 to NskinMenu.Count - 1 do
  begin
    NskinMenu.Items[I].Checked:=false;
  end;
  TMenuItem(Sender).Checked:=true;
end;

end.

⌨️ 快捷键说明

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