Solved

Delphi wait until sound file has played

Posted on 2013-11-26
10
838 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 25

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
 
LVL 19

Expert Comment

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

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 30

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 25

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How to convert wav to mp3 in delphi 9 137
IExtractImage Delphi 14 166
Delphi XE10, MySQL Query 4 109
Intraweb download file link ? 1 88
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

757 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

22 Experts available now in Live!

Get 1:1 Help Now