Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Delphi wait until sound file has played

Posted on 2013-11-26
10
Medium Priority
?
1,044 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
Industry Leaders: 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 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

715 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