[fpc-pascal]Playing sounds in Fpc?

Thomas Schatzl tom_at_work at yline.com
Wed Jul 18 12:18:25 CEST 2001

From: "Andreas K. Foerster" <AKFoerster at nikocity.de>
Subject: Re: [fpc-pascal]Playing sounds in Fpc?

> Michael Lang wrote:
> > [code to play wave and midi files]
> It's very primitive, but it works for win32:
>    uses Dos;
>    procedure PlayWave(WaveFile:String);
>    begin
>      exec('C:\Windows\sndrec32.exe', '/play /close /embedding
> '+WaveFile);
>    end;
> Does anybody know the equivalent parameters for the "media player"?

Better use the Win32 PlaySound() method. It allows playback of all types of
sound files registered within windows.

{$mode delphi}

procedure PlayMediaFile(file : String);
    // plays a sound in background from a file
    PlaySound(file, 0, SND_ASYNC or SND_FILENAME);

should do the trick.

There are a lot more flags for this api call, like playing the sound from
memory or resource, looping it or stop playing - it's probably best to check
out the Win32 help for this function.
If you want a bit more control about the way the sound is played read the
Media Control Interface (MCI) documentation. You may create some sort of
"media player" using it easily (including video playback etc).
Else you could try the DirectSound / DirectMusic API as well for most
playback control.


More information about the fpc-pascal mailing list