Solved

Delphi wait until sound file has played

Posted on 2013-11-26
10
949 Views
Last Modified: 2013-11-28
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.
0
Comment
Question by:oferlll
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
10 Comments
 
LVL 19

Expert Comment

by:MerijnB
ID: 39678816
Do you have the audio in a .wav file or in memory?
0
 

Author Comment

by:oferlll
ID: 39678924
In a file.
0
 
LVL 27

Expert Comment

by:Sinisa Vuk
ID: 39678995
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Expert Comment

by:MerijnB
ID: 39679015
lol. sinisav a little earlier :)
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 39679041
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
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 39679046
Hi all. And me a bit later... :)
0
 

Author Comment

by:oferlll
ID: 39679228
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
 
LVL 19

Expert Comment

by:MerijnB
ID: 39679233
That's odd, can you post a complete function? I'll test tomorrow
0
 
LVL 27

Accepted Solution

by:
Sinisa Vuk earned 500 total points
ID: 39679581
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
 
LVL 19

Expert Comment

by:MerijnB
ID: 39680032
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

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question