M
mike1031
Unregistered / Unconfirmed
GUEST, unregistred user!
我要连续播放wav文件,用循环在字符串中取字匹配wav文件名,用mediaplayer的,可是每次都只放最后一个声音,原因是刚放声音循环又取得下一个文件名,第一个声音还没有放就放下一个拉!我在循环前加判断也不行,大家帮我看看!谢谢!分不够再加!~~部分原码如下:
procedure TForm1.Button1Click(Sender: TObject);
var h,s,a:string;
sStr:string;
x,i:integer;
bChina:Boolean;
procedure Sing(sStr:String);
//产生声音
var sWav:String;
begin
sWav:='mus/wav_'+sStr+'.wav';
if sStr='' then
exit;
try
if ((sStr=' ') or (sStr=',') or (sStr='.') or (sStr=';') or (sStr='!')) then
begin
mediaplayer1.Close;
mediaplayer1.FileName:=apppath+'mus/wav_.wav';
mediaplayer1.Open;
mediaplayer1.play;
end //停止一会
else
begin
mediaplayer1.Close;
mediaplayer1.FileName:=apppath+sWav;
mediaplayer1.Open;
mediaplayer1.play;
end;
except
Showmessage('语音库中没有下列文件:wav_'+sStr+'.wav');
end;
end;
begin
a:=combobox3.Text;
i:=strtoint(a);
h:=combobox2.text;
s:=DBEdit1.Text+combobox2.text ;
end;
for x:=0 to ido
begin
sStr:=s;
bChina:=False;
while length(sStr)>0do
//判断文本是否结束
begin
s:='';
if ((Copy(sStr,1,1)='<') or (bChina=True)) and (Copy(sStr,1,1)<>'>') then
//判断标识符
begin
bChina:=True;
if Copy(sStr,1,1)='<' then
sStr:=Copy(sStr,2,length(sStr));
s:=Copy(sStr,1,2);
sStr:=Copy(sStr,3,length(sStr));
end
else
if (Copy(sStr,1,1)='>') or (bChina=False) then
//判断标识符
begin
bChina:=False;
if Copy(sStr,1,1)='>' then
sStr:=Copy(sStr,2,length(sStr));
if Copy(sStr,1,1)<>'<' then
begin
s:=Copy(sStr,1,1);
sStr:=Copy(sStr,2,length(sStr));
end;
end;
Sing(s);
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Apppath:=ExtractFilepath(Application.ExeName);//获取当前的目录
if apppath[length(apppath)]<>'/' then
apppath:=apppath+'/';
end;
end.
procedure TForm1.Button1Click(Sender: TObject);
var h,s,a:string;
sStr:string;
x,i:integer;
bChina:Boolean;
procedure Sing(sStr:String);
//产生声音
var sWav:String;
begin
sWav:='mus/wav_'+sStr+'.wav';
if sStr='' then
exit;
try
if ((sStr=' ') or (sStr=',') or (sStr='.') or (sStr=';') or (sStr='!')) then
begin
mediaplayer1.Close;
mediaplayer1.FileName:=apppath+'mus/wav_.wav';
mediaplayer1.Open;
mediaplayer1.play;
end //停止一会
else
begin
mediaplayer1.Close;
mediaplayer1.FileName:=apppath+sWav;
mediaplayer1.Open;
mediaplayer1.play;
end;
except
Showmessage('语音库中没有下列文件:wav_'+sStr+'.wav');
end;
end;
begin
a:=combobox3.Text;
i:=strtoint(a);
h:=combobox2.text;
s:=DBEdit1.Text+combobox2.text ;
end;
for x:=0 to ido
begin
sStr:=s;
bChina:=False;
while length(sStr)>0do
//判断文本是否结束
begin
s:='';
if ((Copy(sStr,1,1)='<') or (bChina=True)) and (Copy(sStr,1,1)<>'>') then
//判断标识符
begin
bChina:=True;
if Copy(sStr,1,1)='<' then
sStr:=Copy(sStr,2,length(sStr));
s:=Copy(sStr,1,2);
sStr:=Copy(sStr,3,length(sStr));
end
else
if (Copy(sStr,1,1)='>') or (bChina=False) then
//判断标识符
begin
bChina:=False;
if Copy(sStr,1,1)='>' then
sStr:=Copy(sStr,2,length(sStr));
if Copy(sStr,1,1)<>'<' then
begin
s:=Copy(sStr,1,1);
sStr:=Copy(sStr,2,length(sStr));
end;
end;
Sing(s);
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Apppath:=ExtractFilepath(Application.ExeName);//获取当前的目录
if apppath[length(apppath)]<>'/' then
apppath:=apppath+'/';
end;
end.