关于MediaPlayer的应用(50分)

  • 主题发起人 主题发起人 haibin_song
  • 开始时间 开始时间
H

haibin_song

Unregistered / Unconfirmed
GUEST, unregistred user!
我想在Label2中显示所播放歌曲的时间长度,为什么时间老是不对,有时候一首歌竟然显示出
有120个小时,请各位富翁指点一下。

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, MPlayer,MMSystem;

type
TForm1 = class(TForm)
MediaPlayer1: TMediaPlayer;
Label1: TLabel;
Button1: TButton;
OpenDialog1: TOpenDialog;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
procedure MediaPlayer1Click(Sender: TObject; Button: TMPBtnType;
var DoDefault: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
type

HMSRec = record
NotUsed: byte;
Seconds: byte;
Minutes: byte;
Hours: byte;
end;
var
Form1: TForm1;
Lon: Longint;
const
HMSFormatStr='%d小时%d分钟%d秒 ';

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
MediaPlayer1.FileName:=OpenDialog1.FileName;
MediaPlayer1.Open;
end;
end;

procedure TForm1.MediaPlayer1Click(Sender: TObject; Button: TMPBtnType;
var DoDefault: Boolean);
begin
MediaPlayer1.TimeFormat:=tfSMPTE24;
Lon:=MediaPlayer1.Length;
Label1.Caption:=IntToStr(Lon);
with HMSRec(Lon) do { Typecast TheLength as a HMSRec record }
Label2.Caption:=Format(HMSFormatStr,[Hours,Minutes,Seconds]);
end;

end.
 
后退
顶部