Recent

Author Topic: [SOLVED] Window SDL2 Drop Files  (Read 6853 times)

Pe3s

  • Hero Member
  • *****
  • Posts: 533
[SOLVED] Window SDL2 Drop Files
« on: January 28, 2023, 11:02:57 am »
Hello forumers, what do I need to do to make sdl window support file drop ?
« Last Edit: February 21, 2023, 05:15:52 pm by Pe3s »

metis

  • Sr. Member
  • ****
  • Posts: 300
Re: Window SDL2 Drop Files
« Reply #1 on: January 31, 2023, 03:26:03 pm »
Add a SDL-EventLoop, like...

Code: [Select]
uses
  sdl2, …

var
  aSdlEvent: TSDL_Event;
...

while True do
begin

  SDL_WaitEvent(@aSdlEvent);

  case aSdlEvent.type_ of

    SDL_DROPFILE:
    begin
      ...
    end;

  end;

end;
« Last Edit: February 01, 2023, 01:35:42 pm by metis »
Life could be so easy, if there weren't those f*** Details.
My FFmpeg4Lazarus = FFPlay4Laz + FFGrab4Laz + FFInfo4Laz

Pe3s

  • Hero Member
  • *****
  • Posts: 533
Re: Window SDL2 Drop Files
« Reply #2 on: January 31, 2023, 07:13:34 pm »
@metis you can combine code with sdl drop files
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormDropFiles(Sender: TObject; const FileNames: array of string);
  2. var
  3.   i: Integer;
  4. begin
  5.   for i:= Low(FileNames) to High(FileNames) do
  6.   OpenVideo(FileNames[i]);
  7. end;  
  8.  

metis

  • Sr. Member
  • ****
  • Posts: 300
Re: Window SDL2 Drop Files
« Reply #3 on: January 31, 2023, 07:35:01 pm »
@Pe3s

Your Code is for how to do it with a LCL-Form, but You asked how to do it with a SDL2-Window.  ;D
Life could be so easy, if there weren't those f*** Details.
My FFmpeg4Lazarus = FFPlay4Laz + FFGrab4Laz + FFInfo4Laz

Pe3s

  • Hero Member
  • *****
  • Posts: 533
Re: Window SDL2 Drop Files
« Reply #4 on: February 01, 2023, 07:54:57 pm »
@metis is it possible to write a video file renderer to support LCLForm?

metis

  • Sr. Member
  • ****
  • Posts: 300
Re: Window SDL2 Drop Files
« Reply #5 on: February 02, 2023, 02:49:09 pm »
@Pe3s

If I get You right, you're asking, if it is possible to write a VideoPlayer, that runs inside a LCL-Form.

Yes, it is with a little Help of a VideoPlayback-Library, or (better :D) with my FFmpeg-based Audio/Video-RenderingEngine 'FFPlay4Laz':
The latest Version with SDL2 is here, the latest Version with FFPlay4Laz-Library and Demo-LCL-GUI (but still SDL1) is here.
« Last Edit: February 02, 2023, 03:37:07 pm by metis »
Life could be so easy, if there weren't those f*** Details.
My FFmpeg4Lazarus = FFPlay4Laz + FFGrab4Laz + FFInfo4Laz

Pe3s

  • Hero Member
  • *****
  • Posts: 533
Re: Window SDL2 Drop Files
« Reply #6 on: February 02, 2023, 06:48:48 pm »
@metis, Thank you  :)

Pe3s

  • Hero Member
  • *****
  • Posts: 533
Re: [SOLVED] Window SDL2 Drop Files
« Reply #7 on: February 19, 2023, 12:22:53 pm »
@metis, Hello, you need to write some procedure for this method that handles dropping files, because it doesn't work with Dropfiles?

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormDropFiles(Sender: TObject; const FileNames: array of string);
  2. var
  3.   aSdlEvent: TSDL_Event;
  4. begin
  5.   while True do
  6.   begin
  7.     SDL_WaitEvent(@aSdlEvent);
  8.     case aSdlEvent.type_ of
  9.       SDL_DROPFILE: begin
  10.         OpenVideo(FileNames[0]);
  11.       end;
  12.     end;
  13.   end;
  14. end;
  15.  
« Last Edit: February 19, 2023, 04:23:43 pm by Pe3s »

metis

  • Sr. Member
  • ****
  • Posts: 300
Re: Window SDL2 Drop Files
« Reply #8 on: February 19, 2023, 05:03:56 pm »
See here, and GoTo "For how it's done, take a Look at that MediaPlayer's BasicStructure (Projectname: 'FFPlay4Laz')".
There You will find the complete FPC-Code to open SDL1- resp. SDL2-Windows and write EventLoops for them.
For the Dropfile-Event in particular, see here.

And, don't mix up
DropFile on a LCL-Form (that's, what You're trying all the Time ;D) with
DropFile on a SDL-Window (that's, what You've been asking for in Your OP).
« Last Edit: February 20, 2023, 01:48:35 pm by metis »
Life could be so easy, if there weren't those f*** Details.
My FFmpeg4Lazarus = FFPlay4Laz + FFGrab4Laz + FFInfo4Laz

Pe3s

  • Hero Member
  • *****
  • Posts: 533
Re: Window SDL2 Drop Files
« Reply #9 on: February 20, 2023, 05:43:28 pm »
Probably that's why I think wrong because the sdl window is displayed on the lcl form.
Regards

metis

  • Sr. Member
  • ****
  • Posts: 300
Re: Window SDL2 Drop Files
« Reply #10 on: February 20, 2023, 08:50:16 pm »
Obviously, You attempt to code a VideoPlayer.
Why don't You simply take e.g. the VLC-Component as explained here:
http://lazplanet.blogspot.com/2018/01/how-to-make-simple-video-player-in.html.
It comes together with a complete Lazarus-Project - see the Attachment.
(I took out the Executable to get under the 500KB-Limit for Attachments.)
« Last Edit: February 20, 2023, 09:21:28 pm by metis »
Life could be so easy, if there weren't those f*** Details.
My FFmpeg4Lazarus = FFPlay4Laz + FFGrab4Laz + FFInfo4Laz

Pe3s

  • Hero Member
  • *****
  • Posts: 533
Re: Window SDL2 Drop Files
« Reply #11 on: February 21, 2023, 05:15:36 pm »
@metis, However, I will read more about SDL. Thank you for your patience. Regards

metis

  • Sr. Member
  • ****
  • Posts: 300
Re: [SOLVED] Window SDL2 Drop Files
« Reply #12 on: February 21, 2023, 06:17:53 pm »
You're welcome.  :)

Start with the Tutorials by 'Free Pascal meets SDL':
https://www.freepascal-meets-sdl.net/sdl-tutorials/
« Last Edit: February 22, 2023, 01:52:56 pm by metis »
Life could be so easy, if there weren't those f*** Details.
My FFmpeg4Lazarus = FFPlay4Laz + FFGrab4Laz + FFInfo4Laz

Pe3s

  • Hero Member
  • *****
  • Posts: 533
Re: [SOLVED] Window SDL2 Drop Files
« Reply #13 on: April 23, 2023, 12:38:33 pm »
Hello @Metis, I looked at the source of your gui project and there is code to handle the drop file from the panel where the movie is displayed
What am I doing wrong that my code doesn't work?
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormDropFiles(Sender: TObject; const FileNames: array of string);
  2. begin
  3.   if (Application.GetControlAtMouse.Name = 'pnlScreen') then
  4.   begin
  5.     OpenVideo(FileNames[0]);
  6.   end;
  7. end;
  8.  

metis

  • Sr. Member
  • ****
  • Posts: 300
Re: [SOLVED] Window SDL2 Drop Files
« Reply #14 on: April 23, 2023, 02:12:12 pm »
This Way, the first String in the Array of FileNames, that is dropped on Your LCL-Form is passed to 'OpenVideo()'.
But, what happens then in Your Code ?
What is 'OpenVideo()' doing ? (more than "it opens the video", please)

Hint:
This Code only works as long as the SDL-Window is not captured by the FFPlay4Laz-GUI.
Then, the Code above receives the FileNames, which are dropped on the captured SDL-Window.
(Note: This is not implemented in the FFPlay4Laz1-GUI, but it's proyected in the FFPlay4Laz2-GUI.)

Tip:
To answer to Your Questions, I/we need much more Infos.
It would be much easier, if You attach (Parts of) Your Code.  ;)
Life could be so easy, if there weren't those f*** Details.
My FFmpeg4Lazarus = FFPlay4Laz + FFGrab4Laz + FFInfo4Laz

 

TinyPortal © 2005-2018