Solved

Play .wav one by one

Posted on 2001-07-13
4
498 Views
Last Modified: 2010-04-06
Hi,
How can I play the wave files one by one?  Currently, I use sndPlaySound to play wave files:

procedure TForm1.Button1Click(Sender: TObject);
begin
     sndPlaySound(pchar(wavefile),SND_ASYNC);
     //wavefile is the filename obtained from
     //elsewhere of the program, changes continuously
end;

However, if the user click the button again while a wave is still being played, the playing wave will be stopped immediately, and the new wave will be played.
What I want is: to ignore (NOT put the play requests in a queue) the button click until the wave file is finished.

Thank you.
0
Comment
Question by:nyt
4 Comments
 
LVL 3

Expert Comment

by:tongalite
ID: 6280229
Hi, Below is some code that should help you get what you need. I used 3 wave files on my desktop, adjust the path/directory as neccessary to your own wav.files.
Hope this helps you.
T.
***********************************************

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, MPlayer;

type
  TForm1 = class(TForm)
    MediaPlayer1: TMediaPlayer;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin

  with MediaPlayer1 do
  begin
    FileName := 'C:\windows\desktop\swish1.wav';
    AutoRewind := True;
    try
      Open;          { Open Media Player }
      Wait := True;  { Waits until sounds is done playing to return }
      Play;          { Play sound }
      Play;          { Play again after first playing is completed }
    finally
      Close;             { Close media player }
    end;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  with MediaPlayer1 do
  begin
    FileName := 'C:\windows\desktop\step.wav';
    AutoRewind := True;
    try
      Open;          { Open Media Player }
      Wait := True;  { Waits until sounds is done playing to return }
      Play;          { Play sound }
      Play;          { Play again after first playing is completed }
    finally
      Close;             { Close media player }
    end;
  end;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  with MediaPlayer1 do
  begin
    FileName := 'C:\windows\desktop\slip.wav';
    AutoRewind := True;
    try
      Open;          { Open Media Player }
      Wait := True;  { Waits until sounds is done playing to return }
      Play;          { Play sound }
      Play;          { Play again after first playing is completed }
    finally
      Close;             { Close media player }
    end;
  end;
end;

end.
0
 
LVL 22

Expert Comment

by:mnasman
ID: 6281521
Hello

  try this api with two parametrs :
  snd_sync or snd_nostop

  I didn't test it, cuz my sound card not working :(

  also try to use PlaySound api instead of sndplaysound, cuz it's the new version and it found for backward compatibility, and it's subset of PlaySound


Best regards
Mohammed Nasman
0
 
LVL 1

Accepted Solution

by:
Indefrei earned 30 total points
ID: 6291313
Hi
just use the tmediaplayer and OnClick of whatever
check

    case Mediaplayer1.mode of

    mpPlaying :
     begin
        Timer1.Enabled := True; // ignore ( do what you want)
     end;
    mpStopped :
     begin
        Mediaplayer1.play;
     end;
    end;

happy go lucky
Indi
0
 

Expert Comment

by:tianqi21
ID: 6303516

procedure TForm1.Button1Click(Sender: TObject);
begin
    screen.cursor := crHourglass;
    try
    sndPlaySound(pchar(wavefile),SND_ASYNC);
    //wavefile is the filename obtained from
    //elsewhere of the program, changes continuously
    finally
        Screen.Cursor := crDefault;  
    end;
end;
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
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: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

10 Experts available now in Live!

Get 1:1 Help Now