请问怎么实现多个声音文件顺序播放(200分)

  • 主题发起人 主题发起人 ilikecs
  • 开始时间 开始时间
I

ilikecs

Unregistered / Unconfirmed
GUEST, unregistred user!
我想做一个按照数字自动叫号的东东,比如11号=10.WAV+1.WAV,但是不知道怎么把几个声音文件顺序播放
sndPlaySound(1.wav', SND_ASYNC);

sndPlaySound(2.wav', SND_ASYNC);

sndPlaySound(3.wav', SND_ASYNC);

这样的话只能听到最后一个声音
 
用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):PChar;
public
{ Public declarations }
end;


var
Form1: TForm1;

implementation

{$R *.dfm}

function TForm1.SendMCIStr(const Value: String):PChar;
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:pchar;
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;
 
sndPlaySound(3.wav', SND_ASYNC);

//用PlaySound,不要SND_ASYNC
 
SND_ASYNC表示异步播放,即马上返回(而不是等播放完毕后才返回)
 

Similar threads

I
回复
0
查看
729
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
659
import
I
后退
顶部