Solved

Play .wav one by one

Posted on 2001-07-13
4
502 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
[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 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:Mohammed Nasman
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

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

735 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