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

📄 lyric.pas.~84~

📁 delphi2007写的播放器源码。效果类似于千千静听。
💻 ~84~
字号:
unit Lyric;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls,ComFunction,ComVariable;

type
  TForm3 = class(TForm)
    Timer1: TTimer;
    PaintBox1: TPaintBox;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Timer1Timer(Sender: TObject);
    procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
    procedure LoadLyric;
    procedure Format(str:String);
    procedure ChangeSize;
    procedure Draw(Y:integer;C:TColor;txt:string);
  public
    { Public declarations }
    procedure FindLyric(Name: string;Titles:String);
  end;

var
  Form3: TForm3;
  LineIndex:integer; //正在进行的行索引
  LyricList:TStringList;//歌词列表
  TimeList:TStringList; //时间列表
  FSize:integer; //字体大小
  IsEns:Boolean;//是否有歌词

implementation

{$R *.dfm}

procedure TForm3.ChangeSize;
begin
  paintbox1.Top:=0;
  paintbox1.Left:=0;
  paintbox1.Width:=FSize*34;
  paintbox1.Height:=FSize*5;
  form3.Top:=10;
  form3.Left:=trunc((screen.Width-paintbox1.Width)/2);
  form3.Width:=paintbox1.Width;
  form3.Height:=paintbox1.Height;
end;
procedure TForm3.Draw(Y:integer;C:TColor;txt:string);
var
  W:integer;
begin
    paintbox1.Canvas.Font.Size:=FSize;
    paintbox1.Canvas.Font.Color:=C;
    W:=paintbox1.Canvas.TextWidth(txt);
    W:=trunc((paintbox1.Width-W)/2);
    paintbox1.Canvas.TextOut(W,Y,txt);
end;

procedure TForm3.FindLyric(Name: string;Titles:String);
var
  Temp:string;
begin
    LyricName:='';
    LyRicList.Clear;
    TimeList.Clear;

    temp:=copy(Name,(LastDelimiter('\',Name))+1,length(Name));
    temp:=Copy(temp,1,Length(temp)-4);
    MakeFileList(Path+'LRC\','.lrc',temp,true);
    if LyricName='' then
      MakeFileList(Path+'LRC\','.lrc',Titles,true);
    
    if LyricName<>'' then
    begin
      LoadLyric;
      LineIndex:=0;
      Timer1.Enabled:=true;
      IsEns:=true;
      paintbox1.Canvas.FillRect(paintbox1.ClientRect);
      //dll窗体设置为最前SetWindowPos
      //SetForegroundWindow(form3.Handle);
      //BringWindowToTop(form3.Handle);
    end
    else
    begin
      Timer1.Enabled:=false;
      IsEns:=False;
    end;
end;

procedure TForm3.FormDestroy(Sender: TObject);
begin
  TimeList.Free;
  LyricList.Free;
end;

procedure TForm3.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if Shift = [ssLeft] then
  begin
    ReleaseCapture;
    Perform(WM_SYSCOMMAND, $f012, 0);
  end;
end;

procedure TForm3.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  if Shift = [ssLeft] then
  begin
    ReleaseCapture;
    Perform(WM_SYSCOMMAND, $f012, 0);
  end;
end;

function RoundEx (const Value: Real): integer;
var
  x: Real;
begin
  x := Value - Trunc(Value);
  if x >= 0.5 then
    Result := Trunc(Value) + 1
  else Result := Trunc(Value);
end;

//前进
procedure Rev;
label
  Advance;
begin

Advance:
    if RoundEx(NowTime)>RoundEx(strtofloat(TimeList[LineIndex])) then
    begin
      if (LineIndex+1)<=TimeList.Count-1 then
      begin
        LineIndex:=LineIndex+1;
        goto Advance;
      end;
    end;
end;
//倒退
procedure Adv;
label
  Reverse;
begin

Reverse:
  if LineIndex<=0 then Exit;
  if RoundEx(NowTime)<RoundEx(strtofloat(TimeList[LineIndex-1])) then
  begin
    if (LineIndex-1)>=0 then
    begin
      LineIndex:=LineIndex-1;
      goto Reverse;
    end;
  end;
end;
procedure TForm3.Timer1Timer(Sender: TObject);
begin
  if not isPlay then Exit;
  if not IsEns then Exit;
  if (LineIndex<=TimeList.Count-1) then
  begin
    Rev;
    Adv;

    if RoundEx(NowTime)=RoundEx(strtofloat(TimeList[LineIndex])) then
    begin
       paintbox1.Canvas.FillRect(paintbox1.ClientRect);
       Draw(12,$0000FF,LyricList[LineIndex]);
       LineIndex:=LineIndex+1;
    end;
    if (LineIndex<=TimeList.Count-1) then
      Draw(FSize*2,$00FF00,LyricList[LineIndex])
      else
      Draw(FSize*2,$00FF00,'')
  end;


  if (LineIndex>TimeList.Count-1) then
  begin
    timer1.Enabled:=false;
    Exit;
  end;
end;

procedure TForm3.LoadLyric;
var
  lsttemp:TStringList;
  strTemp:string;
  I,J:integer;
begin
  if not FileExists(LyricName) then Exit;

  lstTemp:=TStringList.Create;
  lsttemp.LoadFromFile(LyricName);
  for I := 0 to lsttemp.Count - 1 do
  begin
    if lstTemp[I]='' then Break;

    if (Pos('[0',lstTemp[I])>0) then
    begin
      Format(lstTemp[I]);
    end;
  end;

  //排序
  for I := 0 to TimeList.Count - 1 do
  begin
    for J := 0 to TimeList.Count - 1 do
    begin
       if strtofloat(TimeList[J]) > strtofloat(TimeList[I]) then
      begin
        strTemp:=TimeList[I];TimeList[I]:=TimeList[J];TimeList[J]:=strTemp;
        strTemp:=LyricList[I];LyricList[I]:=LyricList[J];LyricList[J]:=strTemp;
      end;
    end;
  end;
  lstTemp.Free;
end;

procedure TForm3.FormCreate(Sender: TObject);
begin
  FSize:=16;
  ChangeSize;
  IsEns:=False;
  form3.Show ;
  //窗口强制刷新
  //UpdateWindow(form3.Handle);
  //设置窗口位置
  SetWindowPos(form3.Handle, HWND_TOPMOST, self.Left,
      self.Top, self.Width, self.Height,0);// SWP_NOMOVE Or SWP_NOSIZE);

  TimeList:=TStringList.Create;
  LyricList:=TStringList.Create;
end;

function LastPos(const subStr, s:string):integer;
  var
    iPos:Integer;
    strTmp:Widestring;
  begin
    Result:=0;
    strTmp:=s;
    iPos:=Pos(SubStr,strTmp);
    while iPos<>0 do
    begin
      //删除已经查找过的字符
      Delete(strTmp,1,iPos+Length(SubStr)-1);
      Result:=Result+iPos;
      iPos:=Pos(SubStr,strTmp);
      if iPos=0 then Break;
      Result:=Result+Length(SubStr)-1;
    end;
  end;

function StrToNumber(s:string):String;
var
Temp:double;
begin
  temp:=strtofloat(Copy(s,1,Pos(':',s)-1))*60.0;
  temp:=temp+strtofloat(Copy(s,Pos(':',s)+1,Pos('.',s)-1));
  Result:=floattostr(temp);
end;

procedure TForm3.Format(str: string);
begin
  TimeList.Add(StrToNumber(Copy(str,Pos('[',str)+1,Pos(']',str)-1)));
  LyricList.Add(Copy(str,LastPos(']',str)+1,Length(str)));

  str:=Copy(str,Pos(']',str)+1,Length(str));

  if (Pos('[',str)>0) then
    Format(str);
end;

end.

⌨️ 快捷键说明

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