Listing the audio and video capture devices using FireMonkey 2

Posted by on in Blogs
RAD Studio XE3 includes new classes for identifying, managing and using the audio and video capture devices that are available on your target Windows and Mac computers.  In a previous blog post I showed you how write code that captures audio in a FireMonkey 2 Windows and Mac application.  In this blog post I show you how to list all of the audio and video capture devices that are available on a computer (you can do this using Delphi and C++Builder).  On my Mac, this code will find several audio capture devices, and the built-in camera.  The following is the output from the program when running on a MacBook Pro:



Here is the Delphi code used to display the devices in the bitmap above on my MacBook Pro:
uses
System.SysUtils, System.Types, System.UITypes, System.Rtti, System.Classes,
System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.Layouts,
FMX.Memo, FMX.Media;

type
TForm3 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Label1: TLabel;
Button2: TButton;
Label2: TLabel;
Memo2: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
NumberOfDevices : integer;
public
{ Public declarations }
end;

implementation
{$R *.fmx}
uses System.TypInfo;

procedure TForm3.Button1Click(Sender: TObject);
var
i : integer;
begin
// get the number of audio and video capture devices - if any
NumberofDevices := TCaptureDeviceManager.Current.Count;
Label1.Text := 'Devices: '+IntToStr(NumberOfDevices);
Memo1.Lines.Clear;
// for each capture device, display the index, name, media type and the state
for i := 0 to NumberOfDevices-1 do begin
Memo1.Lines.Add(
IntToStr(i)
+ ': "'
+ TCaptureDeviceManager.Current.Devices[i].Name
+ '", Type: '
+ GetEnumName(System.TypeInfo(TMediaType),
Ord(TCaptureDeviceManager.Current.Devices[i].MediaType))
+ ', State: '
+ GetEnumName(System.TypeInfo(TCaptureDeviceState),
Ord(TCaptureDeviceManager.Current.Devices[i].State))
);
end;
end;

You can use TCaptureDeviceManager to provide user choices of the audio and video devices to use. On my Samsung Slate 7, running Windows 8 Professional, the code finds one audio capture device and two video cameras. I can use this information to provide a choice of which camera to use to grab video frames.

Have fun working with your audio and video capture devices using RAD Studio XE3 and FireMonkey 2.
About
Gold User, Rank: 1, Points: 2466
David Intersimone (known to many as David I.) is a passionate and innovative software industry veteran-often referred to as a developer icon-who extols and educates the world on Embarcadero developer tools. He shares his visions as an active member of the industry speaking circuit and is tapped as an expert source by the media. He is a long-standing champion of architects, developers and database professionals and works to ensure that their needs are folded into Embarcadero's strategic product plans. David holds a bachelor's degree in computer science from California Polytechnic State University at San Luis Obispo, California.
Comments are not available for public users. Please login first to view / add comments.