Delphi: Play sound contained in memorystream

PHOTO EMBED

Sun Aug 28 2022 22:13:00 GMT+0000 (Coordinated Universal Time)

Saved by @marcopinero

var
Form1: TForm1;
ms: TMemoryStream;

:

procedure PlayWaveStream(Stream: TMemoryStream);
begin
  if Stream = nil then
    sndPlaySound(nil, SND_ASYNC) //stop sound
  else
    sndPlaySound(Stream.Memory, (SND_ASYNC or SND_MEMORY));
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ms.LoadFromFile('c:\Eddie\winner.wav');
  ms.Position := 0;
  PlayWaveStream(ms);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  ms := TMemoryStream.Create;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  ms.Free;
end;
content_copyCOPY