Solved

Play .wav one by one

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
oracle global variables 4 80
can't find the executable in Simulator 1 130
Browsing a TTreeView in Delphi 5 49
Firemonkey Queue list 1 51
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

752 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