Multimedia Programming/zh CN

This is an old revision of Multimedia Programming/zh CN, edited by Trev at . The current revision is 100232.

Fixed syntax highlighting; removed categories included in template

播放视频

播放器应用程序

一旦你知道了命令行参数,你可以使用TProcessUTF8启动播放器:

uses 
  Classes, ..., LCLProc, UTF8Process;

...

implementation

procedure TMainForm.Button1Click(Sender: TObject);
var
  Player: TProcessUTF8;
begin
  Player:=TProcessUTF8.Create(nil);
  try
    Player.CommandLine:=PathToPlayer+' '+ParametersAndMediaFile;
    Player.Execute;
  finally
    Player.Free;
  end;
end;

例如在Linux下启动的mplayer播放视频:

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

...

implementation

procedure TMainForm.Button1Click(Sender: TObject);
var
  Player: TProcessUTF8;
  Filename: String;
  PlayerPath: String;
  PlayerParams: String;
begin
  Filename:='/home/username/video.mpg';
  PlayerPath:=FindDefaultExecutablePath('mplayer');
  PlayerParams:='"'+Filename+'"';
  Player:=TProcessUTF8.Create(nil);
  try
    Player.CommandLine:=PlayerPath+' '+PlayerParams;
    Player.Execute;
  finally
    Player.Free;
  end;
end;

VFW - Windows视频

在Windows捕捉和播放视频流从电视卡和网络摄像头 VFW API 可以用 SysRec.(维基百科上的VFM)

Linux gtk2/X上的MPlayer

mplayer 是一个开源和免费的电影播放器。 There is a LCL control embedding the mplayer(LCL中可以内嵌入mplayer), 这样你就可以建立你自己的电影播放器​​或者只是播放视频在您的应用程序。你可以在这里下载:

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

播放音频

仅Windows:使用Windows API

你可以使用Windows API播放文件(如wav):

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

自动防故障的方法,这将允许添加的路径和文件名是非拉丁字母(如:中文):

...
uses LazUTF8;
...
sndPlaySound(pchar(UTF8ToWinCP('C:\sounds\测试.wav')), snd_Async or snd_NoDefault);

或者

...
uses LazUTF8;
...
sndPlaySound(pchar(UTF8ToConsole('C:\sounds\测试.wav')), snd_Async or snd_NoDefault);

显然,这不是跨平台

使用音频组件

查看这个页面页面 Audio Component Suite

使用OpenAL库

Delphi的教程可以在这里找到: http://www.noeska.com/doal/tutorials.aspx

Free Pascal 访问OpenAL单元在 fpc/packages/openal 以及 用法示例

BASS

BASS 库可以到这里下载 :http://www.un4seen.com/ 和 http://www.un4seen.com/forum/?topic=8682.0

有一个DJ应用程序,在 Windows, Linux 和 Mac OSX, written with Lazarus and using Bass lib(Lazarus中用Bass库): https://sites.google.com/site/fiensprototyping/

Audiere库

已绑定Delphi,但他们不能工作在FPC:

Audorra 库

Lazarus上工作正常:

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

OMEGA 引擎

OMEGA引擎是一个完整的游戏引擎只一有个文件Omega.dll仅50KB。它可以播放FLAC,OGG,MP3,MP2,AMR和WMA文件。It searches and uses installed audio codecs from the system.(它在系统中搜索已经安装的音频编解码器)

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

这个项目已经停止,它非常容易使用:

Media_Play('Music.mp3', TRUE);

PortAudio

Various bindings for PortAudio, a cross-platform, open source library for audio playback and recording are available.

([PortAudio](http://www.portaudio.com/)是一个跨平台,支持音频播放和录音的开源库。)

对于一些版本查看http://wiki.lazarus.freepascal.org/Multimedia_Programming#Playing_Sounds。 论坛用户FredvS写了一个Pascal单元,可以动态加载PortAudio:http://lazarus.freepascal.org/index.php/topic,17521.0.html

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.

(基本的SDL库提供了一个非常简单的音效系统。最重要的是,SDL的混音器增加了更多的声音API,它建立一个更加灵活的解决方案。)

访问SDL单位库位于 fpc/packages/sdl.

FMOD

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

(它是一个闭源的解决方案。它是免费的但非商业使用软件。要求支付商业使用费用。)

Squall 音效

Lazarus上工作正常: 它具有3D音频和EAX特效,但只支持MP3,OGG和WAV格式。

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

(FPSound是在fpspreadsheet和fpvectorial基础上开发的新库:它具有独立的模块来读取,编写和播放声音文件并编辑的中间表示。查看 [[FPSound]])

UOS (United OpenLib of Sound)

UOS : United OpenLib of Sound. UOS unifies 最好的开源音频库。

UOS可以:

UOS使用PortAudio,SndFile和Mpg123音频库。

包中包含:

http://sites.google.com/site/fiensprototyping/U_OS_Test.tar.gz

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

查看更多