Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Play .wav one by one

Posted on 2001-07-13
4
Medium Priority
?
509 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: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 120 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

916 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