有一种简易方法://新建一个定时器并把本代码放到OnTimer事件中:uses MMSystem;procedure TForm1.Timer1Timer(Sender: TObject);
var
  Trk, Min, Sec: Word;
begin
  with MediaPlayer1 do
  begin
    Trk:= MCI_TMSF_TRACK(Position);
    Min:=MCI_TMSF_MINUTE(Position);
    Sec:=MCI_TMSF_SECOND(Position);
    Label1.Caption:=Format('%.2d',[Trk]);
    Label2.Caption:=Format('%.2d:%.2d',[Min,Sec]);
  end;
end;

解决方案 »

  1.   

    有一种简易方法://新建一个定时器并把本代码放到OnTimer事件中:uses MMSystem;procedure TForm1.Timer1Timer(Sender: TObject);
    var
      Trk, Min, Sec: Word;
    begin
      with MediaPlayer1 do
      begin
        Trk:= MCI_TMSF_TRACK(Position);
        Min:=MCI_TMSF_MINUTE(Position);
        Sec:=MCI_TMSF_SECOND(Position);
        Label1.Caption:=Format('%.2d',[Trk]);
        Label2.Caption:=Format('%.2d:%.2d',[Min,Sec]);
      end;
    end;
      

  2.   

    设定MediaPlayer1.TimeFormat := tfHMS;type
      HMSRec = record
        Hours: byte;
        Minutes: byte;
        Seconds: byte;
        NotUsed: byte;
      end;procedure TForm1.Button1Click(Sender: TObject);
    var
      TheLength: LongInt;
    begin
      { Set time format - note that some devices don’t support tfHMS }
      MediaPlayer1.TimeFormat := tfHMS;
      { Store length of currently loaded media }
      TheLength := MediaPlayer1.Length;
      with HMSRec(TheLength) do { Typecast TheLength as a HMSRec record }
      begin
        Label1.Caption := IntToStr(Hours); { Display Hours in Label1 }
        Label2.Caption := IntToStr(Minutes); { Display Minutes in Label2 }
        Label3.Caption := IntToStr(Seconds); { Display Seconds in Label3 }
      end;
    end;