I currently can only playback my background sound from having my wave file next to my compiled exe. But I actually want to have a single static executable with the wave file inside. Is this possible in Delphi XE2?
This is my code:
SndPlaySound('.\Raw.wav', SND_ASYNC or SND_LOOP);
#This will play the Raw.wav that is next to my program.
You can add the SND_MEMORY flag, and pass a TResourceStream.Memory
pointer as the first parameter.
First, use XE2's Project->Resources and Images
menu item to add a new resource. Give it the path and filename of your .wav file, a resource type of RC_DATA
(it's not in the drop down list, but you can manually type it in), and a resource name you can use at runtime to refer to it. (In my example, I'm using C:\Microsoft Office\Office12\MEDIA\APPLAUSE.WAV
, and giving it a resource name of APPLAUSE
.)
procedure TForm2.Button1Click(Sender: TObject);
var
Res: TResourceStream;
begin
Res := TResourceStream.Create(HInstance, 'APPLAUSE', 'RC_DATA');
try
Res.Position := 0;
SndPlaySound(Res.Memory, SND_MEMORY or SND_ASYNC or SND_LOOP);
finally
Res.Free;
end;
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With