Delphi wait until sound file has played

I am playing with SndPlaySound. I need to wait until the file has played, or to receive some message when it done.

Please advise how to do it.

Thanks.
oferlllAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Sinisa VukConnect With a Mentor Commented:
Try example given by marqusG. sndPlaySound function is old. MS suggest PlaySound:
PlaySound(PChar(sFile),0,SND_SYNC or SND_FILENAME);

Open in new window

0
 
MerijnBSr. Software EngineerCommented:
Do you have the audio in a .wav file or in memory?
0
 
oferlllAuthor Commented:
In a file.
0
2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

 
Sinisa VukCommented:
like this:
uses ...,MMSystem;

sndPlaySound(PChar(sFile), SND_SYNC);

Open in new window

http://msdn.microsoft.com/en-us/library/windows/desktop/dd798676%28v=vs.85%29.aspx
0
 
MerijnBSr. Software EngineerCommented:
lol. sinisav a little earlier :)
0
 
Marco GasiFreelancerCommented:
You should do something like this:

if PlaySound(PChar(FileName),0,SND_SYNC) then
  Shoemessage('Sound played');

Open in new window


See http://msdn.microsoft.com/en-us/library/aa909803.aspx
0
 
Marco GasiFreelancerCommented:
Hi all. And me a bit later... :)
0
 
oferlllAuthor Commented:
I tried the sndPlaySound(PChar(sFile), SND_SYNC) (I wrote it in my question) - but it doesn's stop - it continue to next line.
0
 
MerijnBSr. Software EngineerCommented:
That's odd, can you post a complete function? I'll test tomorrow
0
 
MerijnBSr. Software EngineerCommented:
Agreed with sinisav, below code works sync here:

unit Unit3;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm3 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form3: TForm3;

implementation

uses
  MMSystem;

{$R *.dfm}

procedure TForm3.Button1Click(Sender: TObject);
begin
 PlaySound(PChar('somewave.wav'),0,SND_SYNC or SND_FILENAME);
 Form3.caption := FormatDateTime('zzz', Now());
end;

end.

Open in new window

0
All Courses

From novice to tech pro — start learning today.