Board index » delphi » Play more wavs in a row (without clicking sound between)

Play more wavs in a row (without clicking sound between)

Play more wavs in a row (without clicking sound between)
Hi,
I know this problem is trivial, but I can not make way around it, can
someone help?
Some directions were to look?
Thanx
mirek

I have about 20 small wav files and I need to play them in a row (one after
other, in different order each time,
so it can not by one big wav file). I tried some components, but they make
clicking sound between each file.
The use of DirectX component (simlest way play sound) makes long delay
between sounds and unwanted sounds.

 

Re:Play more wavs in a row (without clicking sound between)


Try this, passing SND_SYNC as the psType parameter;
the routine can be called from another using that
uses a stringlist to hold to filenames (or whatever
technique you prefer)

(Note: HResDLL is a THandle of a resource DLL that's
assumed to be loaded -- you might have to twiddle
the code a bit to accomodate this)

const
   SND_SYNC      = $0000;
   SND_ASYNC     = $0001;
   SND_NODEFAULT = $0002;
   SND_MEMORY    = $0004;

type
  TAudioSource = (FromFile, FromResource);

procedure TForm1.PlayAudio(Source: TAudioSource; AWave : string; psType :
word);
var
    AsciiZ      : array [0..255] of char;
    lpRes       : PChar;
    hRes        : THandle;
    hResInfo    : THandle;
begin
   StrPCopy(AsciiZ, Trim(AWave));
   if Source = FromResource then
      begin
         hResInfo := FindResource(HResDLL, AsciiZ, 'WAVE');
         if hResInfo <> 0 then
            begin
               hRes := LoadResource(HResDLL, hResInfo);
               if hRes <> 0 then
                  begin
                     lpRes := LockResource(hRes);
                     PlaySound(lpRes, 0, psType or SND_MEMORY);
                     UnlockResource(hRes);
                     FreeResource(hRes);
                  end;
            end;
      end
   else
      PlaySound(AsciiZ, 0, psType or SND_NODEFAULT);
end;

Cheers,
Chris W.

Other Threads