用MCISendString打开声音
private
{ Private declarations }
FLength:longint;
{声音长度}
MCIReturn : array[1..128] of char;
filelist:array of string;
{声音文件列表}
fi:integer;
procedure OpenMusic(FileName:string);
procedure MCINotify;
procedure MCIMSG(var msg:TMessage);message MM_MCINOTIFY;
function SendMCIStr(const Value: String)
Char;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TForm1.SendMCIStr(const Value: String)
Char;
var
dwReturn:Longint;
sReturn : array[1..128] of char;
Ret: PChar;
begin
result:=@MCIReturn;
dwReturn:=MCISendString(PChar(Value),result,128,Handle);
end;
procedure TForm1.MCIMSG(var msg:TMessage);
begin
with Msgdo
if (WParam=MCI_NOTIFY_SUCCESSFUL) then
try
MCINotify;
except
Application.HandleException(Self);
end;
end;
procedure TForm1.OpenMusic(FileName:string);
var
fext,MciType:string;
begin
if fileexists(FileName) then
begin
fext:=extractfileext(FileName);
if SameText(fext,'.wav') then
MciType:='WaveAudio'
else
MciType:='MPEGVideo';
SendMciStr('Open "'+FileName+'" type '+MciType+' alias A0');
SendMciStr('set A0 time format milliseconds');
FLength:=strtoint(SendMCiStr('status A0 length'));
SendMciStr('Play A0 notify');
end;
end;
procedure TForm1.MCINotify;
function GetPos:longint;
begin
result:=strtoint(SendMCiStr('status A0 position'));
end;
var
pc
char;
begin
pc:=SendMciStr('Status A0 mode');
if (string(pc)='stopped') or (GetPos>=FLength) then
begin
inc(fi);
if fi<length(filelist) then
OpenMusic(filelist[fi]);
{播放下一个声音文件}
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
fi:=0;
OpenMusic(filelist[fi]);
end;