Multimedia Programming

This is an old revision of Multimedia Programming, edited by Trev at . The current revision is 62446.

/* Playing Sounds */ Added macOS only native solutions

Playing Videos

Several Libraries exist for embedding video playback into applications.

MPlayer for Linux gtk2/X and Windows

mplayer is an open source and free movie player. As part of Lazarus-CCR, 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 the source here:

svn co https://lazarus-ccr.svn.sourceforge.net/svnroot/lazarus-ccr/components/mplayer mplayer

Playing Sounds

Native macOS solutions

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

For more information, read the article about the Audio Component Suite

Using the OpenAL Library

A tutorial for Delphi can be found here: http://www.noeska.com/doal/tutorials.aspx

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

BASS

The BASS library can be downloaded from: http://www.un4seen.com/ and http://www.un4seen.com/forum/?topic=8682.0

There is a DJ application, for Windows, Linux and macOS, written with Lazarus and using Bass lib: https://sites.google.com/site/fiensprototyping/

Audiere Library

Has bindings for Delphi, but they do not work with FPC:

Audorra Library

This library works well with Lazarus:

http://sourceforge.net/projects/audorra/

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.

http://sourceforge.net/projects/omega-engine/files/

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

Media_Play('Music.mp3', TRUE);

PortAudio

Various bindings for PortAudio, a cross-platform, open source library for audio playback and recording are available. See http://wiki.lazarus.freepascal.org/Multimedia_Programming#Playing_Sounds for some versions. Forum user FredvS has written a Pascal unit that dynamically loads PortAudio: http://lazarus.freepascal.org/index.php/topic,17521.0.html Some examples can be found here: http://breakoutbox.de/pascal/pascal.html#PortAudio

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.

FMOD

Is a closed source solution. It is free for use for non-comercial software, but requires the payment of license fees 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.

http://www.afterwarp.net/resources/soundlib

FPSound

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:

uos can use the PortAudio, SndFile, Mpg123, Faad, Mp4ff, OpusFile audio libraries and SoundTouch, Bs2b plug-in library.

Included in the package:

It can play mp3, ogg, wav, flac, m4a, opus, cda files.

http://github.com/fredvs/uos/

SFML/CSFML for FPC

Simple and Fast Multimedia Library aka SFML provides a simple interface to the various components of your PC, to ease the development of games and multimedia applications. It is composed of five modules: system, window, graphics, audio and network.

CSFML headers binding for FPC can be found at https://github.com/DJMaster/csfml-fpc

See also