This example shows how to play a specified sound file in a loop while the program is running.
First add the MMSystem to the uses section of the program, and then add the following code during the initialization of the form:
procedure TForm1.FormCreate(Sender: TObject);
begin
SndPlaySound(’c:\RECYCLE.WAV’,SND_ASYNC or SND_LOOP);
end;
In this way, at the beginning of the program operation, the program will continue to play the sound file C:\RECYCLE through the sndPlaySound function loop. Wav.
The program code is as follows:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, MMSYSTEM;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
SndPlaySound(’c:\RECYCLE.WAV’,SND_ASYNC or SND_LOOP);
end;
end.
Save the file, and then press the F9 key to run the program. The program will play the sound file uninterrupted during the program's operation.
By calling the sndPlaySound function, the reader can play the sound file in his or her own program, but if you specify a parameter Snd_loop, you can loop through the sound file.