Playing sound --- help--- lazarus / 3-General ---------------------------------------------------------------------- albino · 2008-04-07 00:50 Hello friends of lazarus forum: I am a beginner (Windows) and I am trying to play sound from memory. I created a lrs file to store my  "wav files"  but I coudn't play that sounds. I know I have to use playsound but I don't know how to do it . Please can some body help me with a detailed code? Thank you. ---------------------------------------------------------------------- OnixJr · 2008-04-07 02:03 First of all: welcome to Lazarus Forum =) Aswering the question: Please can you put your code here? Otherwise, nobody can help you without give you a complete source... Trying a quick answer: Did you put MMSystem on uses clauses? (I'm thinking that you are running Lazarus under Windows) Regards, Júnior ---------------------------------------------------------------------- albino · 2008-04-07 20:03 Hello again, thanks for your answer and "sorry" here is my code. I tried this and it works: uses MMSystem; procedure TForm1.Button1Click(Sender: TObject); begin   sndPlaySound('C:\dog.wav',SND_NODEFAULT Or SND_ASYNC); end; Now my problem is loading a lrs file, I wrote this code but it doesn't work. uses MMSystem; initialization {$I unit1.lrs} {$I sounds.lrs} procedure TForm1.Button1Click(Sender: TObject); begin   PlaySound('dog', hInstance, SND_RESOURCE or SND_SYNC); end; Thank you again. ---------------------------------------------------------------------- OnixJr · 2008-04-07 23:21 Hello, AFAIK, PlaySound works with Windows Resources (.res) only. If you want play wav files only under Windows, you can use Windows Resources in PlaySound... Otherwise, you can download/install ACS for Lazarus (Audio Component Suite) to play wav files on cross-plataform (http://wiki.lazarus.freepascal.org/ACS)... PS: I don't know if exists a way to convert LazarusResources (.lrs) to Windows Resources... I did create a example to write lazarus resource to disk and play after. See (I had created a lazarus resource with C:\notify.wav file): Code: [Select] procedure TForm1.Button1Click(Sender: TObject); const   FileName = 'C:\notify.wav'; var   Stream: TFileStream; begin   Stream := TFileStream.Create(FileName, fmCreate);   with LazarusResources.Find('notify') do     Stream.Write(PChar(Value)^, Length(Value));   Stream.Free;   sndPlaySound(FileName, SND_NODEFAULT or SND_ASYNC); end; initialization   {$I unit1.lrs}   {$I C:\notify.lrs} Good Luck Regards, Júnior ---------------------------------------------------------------------- albino · 2008-04-08 05:06 Hello, thanks for your answers. Now I understand .lrs (lazarus) and .res (windows) files are very different. Thank you. ---------------------------------------------------------------------- lazer · 2022-10-13 06:40 This seamed to answer the question nicely but when I add MMSystem it fails to compile: QuoteFatal: Cannot find MMSytem ... Has this been renamed now? Thanks. ---------------------------------------------------------------------- Nicole · 2022-10-13 14:58 There is a component known by the package - online package manager called PlaysoundPackage. Install it. It makes a control appear in the tab "LazControls" called "playsound". Drop it on your form and it works "by itsself" (=intuitive to use). ---------------------------------------------------------------------- KodeZwerg · 2022-10-13 15:14 Quote from: albino on April 07, 2008, 10:03:39 pmHello again, thanks for your answer and "sorry" here is my code. I tried this and it works: uses MMSystem; procedure TForm1.Button1Click(Sender: TObject); begin   sndPlaySound('C:\dog.wav',SND_NODEFAULT Or SND_ASYNC); end; Now my problem is loading a lrs file, I wrote this code but it doesn't work. uses MMSystem; initialization {$I unit1.lrs} {$I sounds.lrs} procedure TForm1.Button1Click(Sender: TObject); begin   PlaySound('dog', hInstance, SND_RESOURCE or SND_SYNC); end; Thank you again. For windows you can do it like here: (add waves in RCDATA section with built-in resource editor) Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);var  resStream: TResourceStream;begin  resStream := TResourceStream.Create(HINSTANCE, 'IDENTIFIER_NAME_OF_WAVE', RT_RCDATA);  try    PlaySound(PChar(resStream.Memory), 0, SND_MEMORY or SND_SYNC);  finally    resStream.Free;  end;end;