delphi 播放wav声音

procedure TForm13.btn1Click(Sender: TObject);
begin
   play_wav_bykeys('1',0);
end;

function TForm13.play_wav_bykeys(filename: string; xflag: Integer): boolean; //  xflag=1 wait play; xflag=0;nowait
const
  SND_DIR  = '.\wav\';
var
  s,f:String;
begin
  sndPlaySound(nil, 0); //停止发音
  s :=Format('%s%s.wav',[SND_DIR,filename]);//播放wav文件夹下filename声音文件

  if FileExists(s) then
  begin
    if xflag = 0 then  sndPlaySound(PChar(s), SND_ASYNC)
    else sndPlaySound(PChar(s), SND_SYNC);
  end;
end;

posted @ 2017-04-06 16:10  夏天的西瓜君  阅读(2544)  评论(0编辑  收藏  举报