Created
July 2, 2015 20:22
-
-
Save marcopin/266c08c88f342a014c3b to your computer and use it in GitHub Desktop.
Delphi: Play sound from memorystream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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