Solved

Delphi wait until sound file has played

Posted on 2013-11-26
10
900 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Firemonkey webbrowser scrollbars ? 1 50
Drag & Drop... Data from one grid to another 2 42
update joined tables 2 55
scroll down TListBox component in Delphi 1 19
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

807 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