C
chechp
Unregistered / Unconfirmed
GUEST, unregistred user!
各位高手:
下面代码是用于获取MP3播放的当前时间和总时间,但是时间显示不正常,不知道哪里错了,请大家指教
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons, ExtCtrls, MPlayer, ComCtrls, StdCtrls, mmsystem;
type
TForm1 = class(TForm)
MediaPlayer1: TMediaPlayer;
Panel1: TPanel;
play: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
OpenDialog1: TOpenDialog;
open: TSpeedButton;
ProgressBar1: TProgressBar;
Timer1: TTimer;
Label1: TLabel;
m: TLabel;
Label2: TLabel;
s: TLabel;
procedure openClick(Sender: TObject);
procedure playClick(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
time,time1:longint;
m,s:byte;
procedure gettotaltime;
procedure showcurrenttime;
type
msfrec = record
Minutes: byte;
Seconds: byte;
frames: byte;
notused: byte;
end;
type
msfrec1=record
Minutes1: byte;
Seconds1: byte;
frames1: byte;
notused1: byte;
end;
implementation
{$R *.dfm}
procedure showcurrenttime;
begin
form1.MediaPlayer1.TimeFormat:=tfmsf;
time1:=form1.MediaPlayer1.Position;
with msfrec1(time1)do
begin
m:=Minutes1;
s:=seconds1;
form1.Label1.Caption:=format('%d:%d',[m,s]);
end;
end;
procedure gettotaltime;
begin
form1.MediaPlayer1.TimeFormat:=tfmsf;
time:=form1.MediaPlayer1.Length;
with msfrec(time)do
begin
form1.m.Caption:=inttostr(minutes);
form1.s.Caption:=inttostr(seconds);
end;
end;
procedure TForm1.openClick(Sender: TObject);
begin
form1.OpenDialog1.Execute;
form1.MediaPlayer1.FileName:=form1.OpenDialog1.FileName;
end;
procedure TForm1.playClick(Sender: TObject);
begin
form1.MediaPlayer1.Open;
form1.ProgressBar1.Min:=0;
form1.ProgressBar1.Max:=form1.MediaPlayer1.Length;
form1.MediaPlayer1.Play;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if form1.MediaPlayer1.Mode=mpplaying then
begin
form1.ProgressBar1.Position:=form1.MediaPlayer1.Position;
gettotaltime;
showcurrenttime;
end;
end;
end.
下面代码是用于获取MP3播放的当前时间和总时间,但是时间显示不正常,不知道哪里错了,请大家指教
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons, ExtCtrls, MPlayer, ComCtrls, StdCtrls, mmsystem;
type
TForm1 = class(TForm)
MediaPlayer1: TMediaPlayer;
Panel1: TPanel;
play: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
OpenDialog1: TOpenDialog;
open: TSpeedButton;
ProgressBar1: TProgressBar;
Timer1: TTimer;
Label1: TLabel;
m: TLabel;
Label2: TLabel;
s: TLabel;
procedure openClick(Sender: TObject);
procedure playClick(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
time,time1:longint;
m,s:byte;
procedure gettotaltime;
procedure showcurrenttime;
type
msfrec = record
Minutes: byte;
Seconds: byte;
frames: byte;
notused: byte;
end;
type
msfrec1=record
Minutes1: byte;
Seconds1: byte;
frames1: byte;
notused1: byte;
end;
implementation
{$R *.dfm}
procedure showcurrenttime;
begin
form1.MediaPlayer1.TimeFormat:=tfmsf;
time1:=form1.MediaPlayer1.Position;
with msfrec1(time1)do
begin
m:=Minutes1;
s:=seconds1;
form1.Label1.Caption:=format('%d:%d',[m,s]);
end;
end;
procedure gettotaltime;
begin
form1.MediaPlayer1.TimeFormat:=tfmsf;
time:=form1.MediaPlayer1.Length;
with msfrec(time)do
begin
form1.m.Caption:=inttostr(minutes);
form1.s.Caption:=inttostr(seconds);
end;
end;
procedure TForm1.openClick(Sender: TObject);
begin
form1.OpenDialog1.Execute;
form1.MediaPlayer1.FileName:=form1.OpenDialog1.FileName;
end;
procedure TForm1.playClick(Sender: TObject);
begin
form1.MediaPlayer1.Open;
form1.ProgressBar1.Min:=0;
form1.ProgressBar1.Max:=form1.MediaPlayer1.Length;
form1.MediaPlayer1.Play;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if form1.MediaPlayer1.Mode=mpplaying then
begin
form1.ProgressBar1.Position:=form1.MediaPlayer1.Position;
gettotaltime;
showcurrenttime;
end;
end;
end.