Forum > General

Playing sound --- help---

(1/2) > >>

albino:
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:
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:
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:
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: ---
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}

--- End code ---


Good Luck
Regards,
Júnior

albino:
Hello, thanks for your answers. Now I understand .lrs (lazarus) and .res (windows) files are very different. Thank you.

Navigation

[0] Message Index

[#] Next page

Go to full version