Solved

Play .wav one by one

Posted on 2001-07-13
4
505 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

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…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month5 days, 3 hours left to enroll

635 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