Skip to content

Instantly share code, notes, and snippets.

@marcopin
Created July 2, 2015 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcopin/266c08c88f342a014c3b to your computer and use it in GitHub Desktop.
Save marcopin/266c08c88f342a014c3b to your computer and use it in GitHub Desktop.
Delphi: Play sound from memorystream
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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment