OldHawk

菜地一块,欢迎拍砖
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Playing a wav file without TMediaPlayer

Posted on 2007-08-20 11:40  OldHawk  阅读(293)  评论(0编辑  收藏  举报
As you know ,to play a WAV sound, you can use a TMediaPlayer object.
This article shows that how can playing a wav file without TMediaplayer.
--------
declared in the mmsystem unit
........
function PlayWav(const FileName: string): Boolean;
begin
Result := PlaySound(PChar(FileName), 0, SND_ASYNC);
end;

procedure StopWav;
var
buffer: array[0..2] of char;
begin
buffer[0] := #0;
PlaySound(Buffer, 0, SND_PURGE);
end;

-------------------------------
//Example:

procedure TForm1.Button1Click(Sender: TObject);
begin
PlayWav('c:\windows\media\start.wav');
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
StopWav;
end;