...
var
Form1: TForm1;
implementation
{$R *.dfm}
type
SoundVar = SND_SYNC .. SND_ASYNC;
procedure SoundPlay(const FileName, Alias, Kind: string; SND: SoundVar);
var
Wt: String;
begin
if SND = SND_SYNC then
Wt := ' wait'
else
Wt := '';
mciSendString
(PChar('open ' + FileName + ' type ' + Kind + ' alias ' + Alias), nil, 0,
Form1.Handle);
mciSendString(PChar('play ' + Alias + ' FROM 0' + Wt), nil, 0, Form1.Handle);
end;
procedure SoundClose(const Alias: string);
begin
mciSendString(PChar('close ' + Alias), nil, 0, Form1.Handle);
end;
procedure CloseAll;
begin
mciSendString('close all', nil, 0, Form1.Handle);
end;
procedure MyPlay(const FileName, Alias: String; SND: SoundVar = SND_ASYNC);
begin
SoundPlay(FileName, Alias, 'waveaudio', SND);
end;
// Beispielaufrufe:
// Drei Waves gleichzeitig spielen
procedure TForm1.Button1Click(Sender: TObject);
begin
MyPlay('Punkte.WAV', 'Points');
MyPlay('D:\Test\Gewonnen.WAV', 'Winner');
MyPlay('C:\neu.WAV', 'Gong');
end;
// Programm wartet bis die erste Wave fertig ist
procedure TForm1.Button2Click(Sender: TObject);
begin
MyPlay('C:\neu.WAV', 'Gong', SND_SYNC);
MyPlay('D:\Test\Gewonnen.WAV', 'Winner');
end;
// Nur ein spezieller Sound wird gestoppt
procedure TForm1.Button3Click(Sender: TObject);
begin
SoundClose('Points');
end;
// Stille
procedure TForm1.Button4Click(Sender: TObject);
begin
CloseAll;
end;