Audio-Video in FireMonkey
Go Up to FireMonkey Application Design
Contents |
FireMonkey XE3 introduces support to capture and play media files (audio-video). This feature is available for Windows and Mac OS X platforms as follows:
- The Windows implementation uses DirectShow, and the audio-video feature works on every Windows version.
- The Mac OS X implementation uses QuickTime and works on OS X versions higher than 10.5.
Supported File Formats
We recommend that you save and use media files in the following formats:
-
.wavon Windows -
.cafon iOS and Mac
You also can play other types of media files, such as MP3 files.
Audio/Video Capture
The base class for capturing devices is TCaptureDevice. This class encapsulates the basic methods and properties for capturing devices. TAudioCaptureDevice and TVideoCaptureDevice extend the TCaptureDevice implementation to add specific behavior for audio capturing devices (like microphones) and respectively video capturing devices (like web cameras).
TCaptureDeviceManager is introduced to access and manage the capturing devices. TCaptureDeviceManager has specific methods and properties to:
- Access devices by type: GetDevicesByMediaType.
- Access the default devices: GetDefaultDeviceByMediaType, DefaultVideoCaptureDevice, DefaultAudioCaptureDevice.
- Access devices by name: GetDevicesByName.
- Get the list of the available media devices: Devices.
The currently used device is specified through the Current property of the device manager. Current is created when an application requests access to TCaptureDeviceManager and is kept until the application is closed.
Code Example
// Delphi declaration var VideoCamera : TVideoCaptureDevice; begin // Get access to the default video capture device VideoCamera := TCaptureDeviceManager.Current.DefaultVideoCaptureDevice; if VideoCamera <> nil then begin //do something end; end;
// C++ declaration TCaptureDeviceManager* CaptureManager = TCaptureDeviceManager::Current; // Get access to the default video capture device TVideoCaptureDevice* VideoCamera = CaptureManager->DefaultVideoCaptureDevice; if(VideoCamera){ //do something }
To start or stop the capture process, you must get access to the device using the TCaptureDeviceManager. Never destroy capture devices explicitly; only the capture manager does that.
TCaptureDeviceManager allows adding custom capture devices developed by third-party vendors. This new device can be restored using the RegisterCaptureDeviceClass method. After registering the new device, it can be accessed as every standard device in TCaptureDeviceManager.
Media Playback
The TMedia class is introduced to support playback for media sources. TMedia exposes media file properties such as file name, size, dimension, state, or duration.
For easy access, the nonvisual component TMediaPlayer is introduced. Call the Play and Stop methods to start playing a media file or to stop or pause a running media file. The current position is specified through the CurrentTime property. TMediaPlayer also exposes media file properties such as Duration, VideoSize, Volume, or State.
To play an audio file using TMediaPlayer, just specify the name of the file to be played by setting the FileName property and calling the Play method. The file name must include the path of the file, so it can be localized on the memory, and the extension.
If the media file is a video file, following the steps above will play only the audio part of the video. To display a video, add a TMediaPlayerControl control, and link TMediaPlayer to it by setting the MediaPlayer property of the TMediaPlayerControl. TMediaPlayerControl is an empty control, but it is used to place video on a form.
Code Example
//Delphi declaration MediaPlayer1.FileName := 'myVideo.avi'; if MediaPlayer1.Media <> nil then begin MediaPlayer1.Play; end;
// C++ declaration MediaPlayer1->FileName="myVideo.avi"; if(MediaPlayer1->Media!=null) { MediaPlayer1->Play(); }
FireMonkey audio/video playback feature offers support for native platform media file formats. Using TMediaCodecManager, it is possible to register custom media codecs to extend the audio/video feature support.