我想做一个CD播放器,如何能够得到CD音轨播放时间的长短和字节大小?(50分)

  • 主题发起人 主题发起人 fullstrong
  • 开始时间 开始时间
F

fullstrong

Unregistered / Unconfirmed
GUEST, unregistred user!
我想做一个CD播放器,如何能够得到CD音轨播放时间的长短和字节大小?

急啊,找不到资料。
 
没人能够告诉我吗?
 
自己还没有写过,这是找来的,你看看

procedure TForm1.Timer1Timer(Sender: TObject);
var sec,min,tr:byte;
begin

sec:=mci_TMSF_Second(Mediaplayer1.Position);
min:=mci_TMSF_Minute(Mediaplayer1.Position);
tr:=mci_TMSF_Track(Mediaplayer1.Position);

if (MediaPlayer1.Tracks=0) or (MediaPlayer1.Tracks>1000) or (MediaPlayer1.Tracks<0) then
label1.caption:=('Please Insert CD') else

begin

if (play=1) or (sec>2) then

begin

label1.caption:=('Track: ')+inttostr(tr)+(' Time: ')+inttostr(min)+(':')+inttostr(sec);
end
else

label1.caption:=('Tracks: ')+inttostr(MediaPlayer1.Tracks);
end;



end;

 
看delphi的demo

 
//这是我从自己的程序中分解出来的一部分,你参看一下
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Player: TMediaPlayer;
ListBox1: TListBox;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
public
end;


var
Form1: TForm1;

implementation

{$R *.dfm}
function GetCDRomPath: ShortString;
var
drives: ShortString;
drvs: Pchar;
x,i: ShortInt;
begin

GetMem(drvs,10);
for i:=0 to 25do

begin

drives:=Chr(65+i)+':/';
Strpcopy(drvs,drives);
x := GetDriveType(drvs);
if x = 5 then

begin

Result := drives;
Exit;
end;

end;

FreeMem(drvs,10);
end;


procedure TForm1.Button1Click(Sender: TObject);
var
I: ShortInt;
Minute, Second: LongInt;
MinuteStr, SecondStr: ShortString;
begin

Player.FileName := GetCDRomPath+'Track01.cda';
//获取光驱盘符
Player.DeviceType := dtCDAudio;
Player.Open;
ListBox1.Clear;
Player.TimeFormat := tfMilliSeconds;
for I:=1 to Player.Tracksdo

begin

Minute := (Player.TrackLength div 1000) div 60;
Second := (Player.TrackLength div 1000) mod 60;
if Minute <10 then

MinuteStr := '0'+IntToStr(Minute)
else
if Minute >=10 then

MinuteStr := IntToStr(Minute);
if Second <10 then

SecondStr := '0'+IntToStr(Second)
else
if Second >=10 then

SecondStr := IntToStr(Second);
if I < 10 then

ListBox1.Items.Add('Track0'+IntToStr(I)+' '+MinuteStr+':'+SecondStr)
else
if I >= 10 then

ListBox1.Items.Add('Track'+IntToStr(I)+' '+MinuteStr+':'+SecondStr);
end;

end;


end.

 

还有没有其他的好方法?
 
自己还没有写过,这是找来的,你看看

procedure TForm1.Timer1Timer(Sender: TObject);
var sec,min,tr:byte;
begin

sec:=mci_TMSF_Second(Mediaplayer1.Position);
min:=mci_TMSF_Minute(Mediaplayer1.Position);
tr:=mci_TMSF_Track(Mediaplayer1.Position);

if (MediaPlayer1.Tracks=0) or (MediaPlayer1.Tracks>1000) or (MediaPlayer1.Tracks<0) then
label1.caption:=('Please Insert CD') else

begin

if (play=1) or (sec>2) then

begin

label1.caption:=('Track: ')+inttostr(tr)+(' Time: ')+inttostr(min)+(':')+inttostr(sec);
end
else

label1.caption:=('Tracks: ')+inttostr(MediaPlayer1.Tracks);
end;



end;




来自:sword_liu, 时间:2001-11-5 13:32:00, ID:707588
看delphi的demo




来自:Sachow, 时间:2001-11-5 13:34:00, ID:707592
//这是我从自己的程序中分解出来的一部分,你参看一下
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Player: TMediaPlayer;
ListBox1: TListBox;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
public
end;


var
Form1: TForm1;

implementation

{$R *.dfm}
function GetCDRomPath: ShortString;
var
drives: ShortString;
drvs: Pchar;
x,i: ShortInt;
begin

GetMem(drvs,10);
for i:=0 to 25do

begin

drives:=Chr(65+i)+':/';
Strpcopy(drvs,drives);
x := GetDriveType(drvs);
if x = 5 then

begin

Result := drives;
Exit;
end;

end;

FreeMem(drvs,10);
end;


procedure TForm1.Button1Click(Sender: TObject);
var
I: ShortInt;
Minute, Second: LongInt;
MinuteStr, SecondStr: ShortString;
begin

Player.FileName := GetCDRomPath+'Track01.cda';
//获取光驱盘符
Player.DeviceType := dtCDAudio;
Player.Open;
ListBox1.Clear;
Player.TimeFormat := tfMilliSeconds;
for I:=1 to Player.Tracksdo

begin

Minute := (Player.TrackLength div 1000) div 60;
Second := (Player.TrackLength div 1000) mod 60;
if Minute <10 then

MinuteStr := '0'+IntToStr(Minute)
else
if Minute >=10 then

MinuteStr := IntToStr(Minute);
if Second <10 then

SecondStr := '0'+IntToStr(Second)
else
if Second >=10 then

SecondStr := IntToStr(Second);
if I < 10 then

ListBox1.Items.Add('Track0'+IntToStr(I)+' '+MinuteStr+':'+SecondStr)
else
if I >= 10 then

ListBox1.Items.Add('Track'+IntToStr(I)+' '+MinuteStr+':'+SecondStr);
end;

end;


end
 
后退
顶部