DavidJr. 1 Posted February 13, 2023 Hi, I am following this example for setting up a VideoCaptureDevice app: https://docwiki.embarcadero.com/RADStudio/Sydney/en/Video_Capturing I could not get the VideoCaptureDevice to start. I tried 4 known good cameras and get the same thing, I modified the code a bit to give me an indicator that I am indeed setting up the app right, still nothing. The app compiles just fine, just won't start capture. My version of Delphi is 10.2.3 and the following is my current code: unit FMXCamera_Main; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Objects, FMX.ListBox, FMX.Controls.Presentation, FMX.StdCtrls, FMX.Layouts, FMX.Media, FMX.Edit; type TForm1 = class(TForm) Layout1: TLayout; btnStart: TButton; ComboBox1: TComboBox; Image1: TImage; procedure FormCreate(Sender: TObject); procedure ComboBox1Change(Sender: TObject); procedure btnStartClick(Sender: TObject); procedure FormDestroy(Sender: TObject); private { Private declarations } public { Public declarations } VideoCamera: TVideoCaptureDevice; procedure SampleBufferSync; procedure SampleBufferReady(Sender: TObject; const ATime: TMediaTime); end; var Form1: TForm1; implementation // Delphi version of the implementation {$R *.fmx} procedure TForm1.btnStartClick(Sender: TObject); begin if(VideoCamera <> nil) then begin if(VideoCamera.State = TCaptureDeviceState.Stopped) then begin VideoCamera.OnSampleBufferReady := SampleBufferReady; VideoCamera.CaptureSettingPriority := TVideoCaptureSettingPriority.FrameRate; VideoCamera.StartCapture; if(VideoCamera.State = TCaptureDeviceState.Capturing) then begin btnStart.Text := 'Stop'; end else begin VideoCamera.StopCapture; btnStart.Text := 'Start'; end; end else begin VideoCamera.StopCapture; btnStart.Text := 'Start'; end; end else begin Caption := 'Video capture devices not available.'; end; end; procedure TForm1.ComboBox1Change(Sender: TObject); begin VideoCamera := TVideoCaptureDevice(TCaptureDeviceManager.Current.GetDevicesByName(ComboBox1.Selected.Text)); if (VideoCamera <> nil) then begin btnstart.Text := 'Start '+VideoCamera.Name; btnStart.Enabled := true; end; end; procedure TForm1.FormCreate(Sender: TObject); var DeviceList: TCaptureDeviceList; i: integer; begin DeviceList := TCaptureDeviceManager.Current.GetDevicesByMediaType(TMediaType.Video); for i := 0 to DeviceList.Count - 1 do begin ComboBox1.Items.Add(DeviceList[i].Name); end; end; procedure TForm1.FormDestroy(Sender: TObject); begin if(VideoCamera <> nil) then begin VideoCamera.StopCapture; end; end; procedure TForm1.SampleBufferReady(Sender: TObject; const ATime: TMediaTime); begin TThread.Synchronize(TThread.CurrentThread, SampleBufferSync); //Resize the image so that the video is buffered in its original size Image1.Width := Image1.Bitmap.Width; Image1.Height := Image1.Bitmap.Height; end; procedure TForm1.SampleBufferSync; begin VideoCamera.SampleBufferToBitmap(Image1.Bitmap, true); end; end. Share this post Link to post
programmerdelphi2k 237 Posted February 14, 2023 (edited) nevermind, sorry! Edited February 14, 2023 by programmerdelphi2k Share this post Link to post
Lars Fosdal 1792 Posted February 14, 2023 You have not identified the type of device, so I assume Android and/or iOS. Has the app requested the right to use the camera? Has approval been given? Ref: https://docwiki.embarcadero.com/RADStudio/Tokyo/en/Uses_Permissions#camera Share this post Link to post
DavidJr. 1 Posted February 14, 2023 6 hours ago, Lars Fosdal said: You have not identified the type of device, so I assume Android and/or iOS. Has the app requested the right to use the camera? Has approval been given? Ref: https://docwiki.embarcadero.com/RADStudio/Tokyo/en/Uses_Permissions#camera Sorry just my luck I'd leave out some information. This is a Windows 10 OS, NOT Android. Share this post Link to post
Lars Fosdal 1792 Posted February 14, 2023 Ah, in that case - ensure there is no other software that might grab the camera instead of your app? Share this post Link to post
DavidJr. 1 Posted February 14, 2023 1 minute ago, Lars Fosdal said: Ah, in that case - ensure there is no other software that might grab the camera instead of your app? I have absolutely done all of that. I am not even getting any errors in the IDE. Share this post Link to post
Lars Fosdal 1792 Posted February 14, 2023 And there is nothing in the code that eats exceptions instead of exposing them? What about stills? Can you get the example to work? Share this post Link to post
DavidJr. 1 Posted February 14, 2023 1 minute ago, Lars Fosdal said: And there is nothing in the code that eats exceptions instead of exposing them? What about stills? Can you get the example to work? The example did not work, The Camera is in a state of "Stopped" after calling "StartCapture" Share this post Link to post
Lars Fosdal 1792 Posted February 14, 2023 What about the Windows permissions? https://support.microsoft.com/en-us/topic/87ebc757-1f87-7bbf-84b5-0686afb6ca6b Share this post Link to post
DavidJr. 1 Posted February 14, 2023 1 hour ago, Lars Fosdal said: What about the Windows permissions? https://support.microsoft.com/en-us/topic/87ebc757-1f87-7bbf-84b5-0686afb6ca6b I have done everything. The camera permissions is open. In VCL I am using other libraries that work just fine. Its the FMX app that doesn't work. Share this post Link to post
Lars Fosdal 1792 Posted February 14, 2023 I spotted this. Not sure if relevant? https://stackoverflow.com/questions/45502430/how-to-access-camera-on-a-windows-tablet-with-firemonkey Share this post Link to post
DavidJr. 1 Posted March 8, 2023 I have abandoned the FMX option. Thanks. Share this post Link to post