Recent

Author Topic: Playing sound --- help---  (Read 8928 times)

albino

  • New member
  • *
  • Posts: 7
Playing sound --- help---
« on: April 07, 2008, 02:50:19 am »
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

  • Full Member
  • ***
  • Posts: 172
    • http://www.brlazarus.kit.net
RE: Playing sound --- help---
« Reply #1 on: April 07, 2008, 04:03:25 am »
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
Portal Lazarus Brasil - http://lazaruspascal.codigolivre.org.br/portal.php
Lazarus BOOK (in portuguese) - http://lazarus-book.blogspot.com
<hipernetjr@yahoo.com.br> - Curitiba/Brazil

albino

  • New member
  • *
  • Posts: 7
Sorry, my code.
« Reply #2 on: April 07, 2008, 10:03:39 pm »
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

  • Full Member
  • ***
  • Posts: 172
    • http://www.brlazarus.kit.net
RE: Sorry, my code.
« Reply #3 on: April 08, 2008, 01:21:53 am »
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
Portal Lazarus Brasil - http://lazaruspascal.codigolivre.org.br/portal.php
Lazarus BOOK (in portuguese) - http://lazarus-book.blogspot.com
<hipernetjr@yahoo.com.br> - Curitiba/Brazil

albino

  • New member
  • *
  • Posts: 7
play sound
« Reply #4 on: April 08, 2008, 07:06:35 am »
Hello, thanks for your answers. Now I understand .lrs (lazarus) and .res (windows) files are very different. Thank you.