Solved

Delphi wait until sound file has played

Posted on 2013-11-26
10
874 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
  • 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 26

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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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 26

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

815 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now