Recent

Author Topic: How can i start ffplay with different urls in a csv file from a combobox?  (Read 877 times)

mathias63

  • New Member
  • *
  • Posts: 17
More question on this ffplayer app that i try to  make :D... one other thing i want to be able to do is open my different urls, selecting them from a combobox that loads all names like "garage", "garden"....but executes them from another column separated with "," in the csv file.

one easy way i found was just doing this:

Code: [Select]
RunProgram.Commandline:=('/bin/ffplay -rtsp_transport tcp -i ' + ComboBox1.Text);
but that just works with a plain text file, reading each row from the file and add it.

tried google it and AI gave some ideas that actually works to just show the titles i gave to the streams, i made on form create:
Code: [Select]
var
   CSVFile: TStringList;
   Line: string;
   Parts: TStringArray; // Using TArray for modern Pascal
   


begin
   ///ComboBox1.Items.LoadFromFile('myfile.csv');
   CSVFile := TStringList.Create;
  try
    // Load the CSV file. Replace 'your_file.csv' with the actual path.
    CSVFile.LoadFromFile('myfile.csv');

    // Clear the ComboBox first if it already has items
    ComboBox1.Clear;

    // Iterate through each line in the CSV file
    for Line in CSVFile do
    begin
      // Split the line by the comma delimiter.
      // The Delimiter parameter is optional, comma is the default for Split.
      Parts := Line.Split([',']);

      // Assuming your CSV has at least one column of data
      if High(Parts) >= 0 then
      begin
        // Add the first part (index 0) of the split line to the ComboBox
        // If you want to add a different part, change the index (e.g., Parts[1])
        ComboBox1.Items.Add(Parts[0]);
      end;
    end;
  finally
    CSVFile.Free; // Always free the created object
  end;

But how do i do to execute the cam url from that csv file?   that exist in the other column.   

Code: [Select]
RunProgram.Commandline:=('/bin/ffplay -rtsp_transport tcp -i ' + ComboBox1........?            
« Last Edit: September 03, 2025, 12:43:46 pm by mathias63 »

creaothceann

  • Full Member
  • ***
  • Posts: 206
Re: How can i start ffplay with different urls in a csv file from a combobox?
« Reply #1 on: September 03, 2025, 12:31:07 pm »
Please use [code][/code]-tags to make the code better visible and also to avoid the forum software potentially interpreting the code.
Quote from: Thaddy
And don't start an argument, I am right.
Quote from: Thaddy
You have a thorough misunderstanding of what I wrote. Can you provide an example this time? I doubt it. (because you never do out of incompentence)

mathias63

  • New Member
  • *
  • Posts: 17
Re: How can i start ffplay with different urls in a csv file from a combobox?
« Reply #2 on: September 03, 2025, 12:37:47 pm »
Please use [code][/code]-tags to make the code better visible and also to avoid the forum software potentially interpreting the code.

Ok did not know how to do it :) will fix that

mathias63

  • New Member
  • *
  • Posts: 17
Re: How can i start ffplay with different urls in a csv file from a combobox?
« Reply #3 on: September 03, 2025, 12:54:00 pm »
Or is it possible to split a line in just a text file with a ","?  for example use a line like this "My Kitchen cam, 192.168.0.50".

But how do i do to get the first parameter as the text in the combobox and then store the url in a string variable so i can execute it?

mathias63

  • New Member
  • *
  • Posts: 17
Re: How can i start ffplay with different urls in a csv file from a combobox?
« Reply #4 on: September 03, 2025, 04:58:39 pm »
Is this even possible? maybe have to use a database?

mathias63

  • New Member
  • *
  • Posts: 17
Re: How can i start ffplay with different urls in a csv file from a combobox?
« Reply #5 on: September 03, 2025, 06:41:25 pm »
Managed to fix it by adding a extra array and use the combobox.itemindex....

Lulu

  • Sr. Member
  • ****
  • Posts: 334
Re: How can i start ffplay with different urls in a csv file from a combobox?
« Reply #6 on: September 03, 2025, 07:50:00 pm »
Or is it possible to split a line in just a text file with a ","?  for example use a line like this "My Kitchen cam, 192.168.0.50".

But how do i do to get the first parameter as the text in the combobox and then store the url in a string variable so i can execute it?

Hi, if I understand well the question (which is not often the case! :D)
Code: Pascal  [Select][+][-]
  1. procedure SplitCam(const aLine: string; out CamName, Url: string);
  2. var A: TStringArray;
  3. begin
  4.   A := aLine.Split([',']);
  5.   CamName := A[0];
  6.   Url := A[1];
  7. end;
  8. ...
  9. // usage:
  10. SplitCam('My Kitchen cam,192.168.0.50'); // << NO SPACE AFTER THE COMMA !
  11.  

Be sure the name of the cams don't contain a coma.
wishing you a nice life!
GitHub repositories https://github.com/Lulu04

mathias63

  • New Member
  • *
  • Posts: 17
Re: How can i start ffplay with different urls in a csv file from a combobox?
« Reply #7 on: September 04, 2025, 06:47:45 pm »
Thanks allot Lulu. I will try your code, even though i managed to make it function in some similar way :).

/Mathias

Lulu

  • Sr. Member
  • ****
  • Posts: 334
Re: How can i start ffplay with different urls in a csv file from a combobox?
« Reply #8 on: September 04, 2025, 07:35:55 pm »
Hi, i've just realized that in the call of procedure SplitCam() the variables are missing. Sorry!
It should be:
Code: Pascal  [Select][+][-]
  1. procedure SplitCam(const aLine: string; out CamName, Url: string);
  2. var A: TStringArray;
  3. begin
  4.   A := aLine.Split([',']);
  5.   CamName := A[0];
  6.   Url := A[1];
  7. end;
  8.     ...
  9. // usage:
  10. var FCamName, FUrl: string;
  11. ...
  12. SplitCam('My Kitchen cam,192.168.0.50', FCamName, FUrl); // << NO SPACE AFTER THE COMMA !
wishing you a nice life!
GitHub repositories https://github.com/Lulu04

 

TinyPortal © 2005-2018