mplayer + sqlite [SOLVED] lazarus / 16-Databases ---------------------------------------------------------------------- Marcelo Confortino · 2016-09-04 13:39 Good morning! I am writing an application that must take a picture of the operator when some event is triggered. So far I have mplayer running and showing a webcam's output on screen (see attached screenshot): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i    {$IFDEF Linux}   MPlayerControl1.MPlayerPath:='';   //MPlayerControl1.StartParam:='-vo x11 -zoom -fs';   MPlayerControl1.Filename := 'tv:// driver=v4l2:device=/dev/video0:gain=1:width=320:height=200:fps=25';   MPlayerControl1.Play;  {$else $IFDEF Windows}   // Download MPlayer generic for Windows and save under Programm Folder Directory   // http://sourceforge.net/projects/mplayer-win32/   //Download MPlayer WIN32-Generic   MPlayerControl1.MPlayerPath:=extractfilepath(applicati on.exename)+'MPlayer\mplayer.exe' ;   //MPlayerControl1.StartParam:='-zoom -fs';   MPlayerControl1.Filename:='tv:// driver=dshow:device=0:gain=1:width=320:height=200:fps=25';   MPlayerControl1.Play;  {$endif}     the code that takes the picture and saves the filename to the database is here: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i       if MPlayerControl1.Running then        begin          MPlayerControl1.GrabImage;          RegistroDataset.FieldByName('imagen').AsString := MPlayerControl1.LastImageFilename;        end;   the problem is that the very first invocation of above code does not save the image filename in the database, later invocations work fine. Am I missing something? Thanks for your advice. ---------------------------------------------------------------------- LacaK · 2016-09-05 08:51 You do not show whole database code  There is missing at least ApllyUpdates and Commit ? ---------------------------------------------------------------------- Marcelo Confortino · 2016-09-05 16:05 Sorry, LacaK. This is the relevant code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i       RegistroDataset.FieldByName('nrodni').AsInteger := StrToInt(Edit1.Text);      RegistroDataset.FieldByName('fechahora').AsString := DateTimeToStr(Now);      if MPlayerControl1.Running then        begin          MPlayerControl1.GrabImage;          RegistroDataset.FieldByName('imagen').AsString := MPlayerControl1.LastImageFilename;        end;      RegistroDataset.Post;      RegistroDataset.ApplyUpdates;  The other fields in the record are saved fine, as is the full record in all but the first execution of the code. Thank you. ---------------------------------------------------------------------- balazsszekely · 2016-09-05 16:48 @Marcelo Confortino Perhaps MPlayerControl1.GrabImage doesn't return the filename immediately. You should wait a few seconds before saving the data into the database. ---------------------------------------------------------------------- Marcelo Confortino · 2016-09-05 18:22 Thank you, GetMem, I'll try that. Is there a way to know when the image file is ready? ---------------------------------------------------------------------- balazsszekely · 2016-09-05 18:48 Apparently LastImageFilename is unique, so this should work: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i //...  TForm1 = class(TForm)  private    function Wait(const DT: QWord; const OldFileName: String): Boolean;  public  end;       //... function TForm1.Wait(const DT: QWord; const OldFilename: String): Boolean;var  TC: QWord;begin  Result := False;  TC := GetTickCount64;  while (GetTickCount64 < TC + DT) and (not Application.Terminated) do  begin    if OldFilename <> MPlayerControl1.LastImageFilename then    begin    Result := True;      Break;    end;    Application.ProcessMessages;  end;end; procedure TForm1.Button1Click(Sender: TObject);var  OldFilename: String;begin  OldFilename:= MPlayerControl1.LastImageFilename;  if MPlayerControl1.Running then  begin     MPlayerControl1.GrabImage;     if Wait(5000, OldFilename) then //wait until the filename changes, but no more then five seconds     begin        //do the saving here     end;  end;end; ---------------------------------------------------------------------- Marcelo Confortino · 2016-09-05 21:23 Wow, that was fast, thank you. Sadly, it doesn't work. I even inserted Wait(5000) between grabimage and lastfilename, same result. Looks like some initialization is missing. Reading the wiki, it seems that TMPlayerControl.GrabImage is not fully dependable. I'll keep working on this. ---------------------------------------------------------------------- Marcelo Confortino · 2016-09-06 11:57 Well. sort of. I added an additional GrabImage just after the initialization of TMplayerControl. Later, when I call GrabImage and LastFilename it is not the first invocation anymore, and it works as intended. Than you all.