[fpc-pascal]Playing sounds in Fpc?

Thomas Schatzl tom_at_work at yline.com
Thu Jul 19 01:40:17 CEST 2001


Subject: [fpc-pascal]Playing sounds in Fpc?


> Hi Thomas,
>
> This doesn't work. Ppc386 says, that it doesn't know the
> PlaySound-Procedure. The "uses windows;" should import it, but it
> doesn't seem to work, at least not on my machine. Does it work on
> anybody else's here?
>

Forgot that the MMSystem header stuff is not already translated for FPC:
Try this code:

{$mode delphi}
uses
 windows;
// flag values for wFlags parameter
const
  SND_SYNC            = $0000;  // play synchronously (default)
  SND_ASYNC           = $0001;  // play asynchronously
  SND_NODEFAULT       = $0002;  // don't use default sound
  SND_MEMORY          = $0004;  // lpszSoundName points to a memory file
  SND_LOOP            = $0008;  // loop the sound until next sndPlaySound
  SND_NOSTOP          = $0010;  // don't stop any currently playing sound
  SND_NOWAIT          = $00002000;  // don't wait if the driver is busy
  SND_ALIAS           = $00010000;  // name is a registry alias
  SND_ALIAS_ID        = $00110000;  // alias is a predefined ID
  SND_FILENAME        = $00020000;  // name is file name
  SND_RESOURCE        = $00040004;  // name is resource name or atom
  SND_PURGE           = $0040;      // purge non-static events for task
  SND_APPLICATION     = $0080;     // look for application specific
association

function PlaySound(pszSound: PChar; hmod: HMODULE; fdwSound: DWORD): BOOL;
stdcall; external 'winmm.dll' name {$ifdef unicode}'PlaySoundW' {$else}
'PlaySoundA' {$endif};


procedure PlayMediaFile(_file : String);
begin
    // plays a sound from a file
    PlaySound(PChar(_file), 0, SND_SYNC or SND_FILENAME);
end;

begin
 PlayMediaFile(paramstr(1));
end.

This works for sure with wav and mp3 files (verified). Doesn't with midi's -
didn't test other.

Regards,
    Thomas





More information about the fpc-pascal mailing list