Multimedia Programming

From Lazarus wiki
Revision as of 08:39, 3 July 2014 by Mike.cornflake (talk | contribs) (Playing Videos: Removed VFW/SysRec (moved to Video Playback Libraries))

Deutsch (de) English (en) 日本語 (ja) 한국어 (ko) русский (ru) 中文(中国大陆)‎ (zh_CN)

Playing Videos

Several Libraries exist for embedding video playback into applications.

Starting a player application

Once you know the command line and parameters you can use TProcessUTF8 to start the player:

  Classes, ..., LCLProc, UTF8Process;



procedure TMainForm.Button1Click(Sender: TObject);
  Player: TProcessUTF8;
    Player.CommandLine:=PathToPlayer+' '+ParametersAndMediaFile;

You don't need to use the TMPlayerControl to control mplayer. For example to play a video with mplayer directly under Linux use: (Similar code will work under Windows, or with ffPlay)

  Classes, ..., FileUtil, LCLProc, UTF8Process;



procedure TMainForm.Button1Click(Sender: TObject);
  Player: TProcessUTF8;
  Filename: String;
  PlayerPath: String;
  PlayerParams: String;
    Player.CommandLine:=PlayerPath+' '+PlayerParams;

MPlayer for Linux gtk2/X and Windows

mplayer is an open source and free movie player. There is a LCL control TMPlayerControl embedding the mplayer, so you can built your own movie players or just play a video in your application. You can download it here:

svn co mplayer

Playing Sounds

Windows only: using the Windows API

You can use the Windows API to play e.g. wav files:

uses MMSystem;
sndPlaySound('C:\sounds\test.wav', snd_Async or snd_NoDefault);

The fail-safe way, which will allow appending paths and nonlatin file names is:

sndPlaySound(pchar(UTF8ToSys('C:\sounds\test.wav')), snd_Async or snd_NoDefault);

Obviously, this is not cross-platform

Using the Audio Component Suite

Read the page about the Audio Component Suite

Using the OpenAL Library

A tutorial for Delphi can be found here: [1]

Free Pascal comes with a unit for accessing OpenAL located in fpc/packages/openal as well as usage examples


The BASS library can be downloaded from: and

There is a DJ application, for Windows, Linux and Mac OSX, written with Lazarus and using Bass lib:

Audiere Library

Has bindings for Delphi, but they don't work with FPC:

Audorra Library

Works fine with Lazarus:

OMEGA Engine

The OMEGA Engine is a full game engine in single Omega.dll file which is just 50kb. It can successfully play FLAC,OGG,MP3,MP2,AMR and WMA files. It searches and uses installed audio codecs from the system.

The project is dead, but is very easy to use:

Media_Play('Music.mp3', TRUE);


Various bindings for PortAudio, a cross-platform, open source library for audio playback and recording are available. See [[2]] for some versions. Forum user FredvS has written a Pascal unit that dynamically loads PortAudio: [3]

SDL + SDL_mixer

The basic SDL library comes with a very simple sound system. On top of that, SDL mixer adds more sound APIs which build a more flexible solution.

Units for accessing SDL libraries are located in fpc/packages/sdl.


Is a closed source solution. It is free for use for non-comercial software, but requires the payment of licenses for commercial software.

Squall sound

Squall sound works fine with FPC. It has 3D audio and EAX effects, but just supports MP3, OGG and WAV formats.


FPSound is a new library being developed in the mold of fpspreadsheet and fpvectorial: it has independent modules to read, write and play sound files and also an intermediary representation for editing. See FPSound

UOS (United OpenLib of Sound)

UOS : United OpenLib of Sound. UOS unifies the best open-source audio libraries.

With UOS you can:

  • Listen to mp3, ogg, wav, flac,... audio files.
  • With 16, 32 or float 32 bit resolution.
  • Record all types of input into file.
  • Add DSP effects and filters, however many you want and record it.
  • Listen to multiple inputs and outputs.

UOS uses the PortAudio, SndFile and Mpg123 audio libraries.

Included in the package:

  • examples.
  • binary libraries for Linux 32/64, Windows 32/64, Mac OSX 32.

See also