Recent

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

Pe3s

  • Hero Member
  • *****
  • Posts: 633
Re: [SOLVED] Window SDL2 Drop Files
« Reply #15 on: April 23, 2023, 03:49:26 pm »
Open video
Code: Pascal  [Select][+][-]
  1. procedure TForm1.OpenVideo(FName: String);
  2. begin
  3.   VPlayer.Stop;
  4.   VPlayer.Url := FName;
  5.   Form1.Caption := ExtractFileName(FName);
  6.   VPlayer.Play;
  7.  
  8.   VPlayer.AudioVolume := volumePosition;
  9. end;
  10.  
  11. [code=pascal]
  12. procedure TForm1.FormCreate(Sender: TObject);
  13. begin
  14.   VPlayer := TPlayer.Create(nil);
  15.   with VPlayer do
  16.     begin
  17.         Align := alClient;
  18.         OnProgress := @Self.UpdateProgress;
  19.         Parent := pnlScreen;
  20.     end;
  21. end;
  22.  
[/code]

metis

  • Sr. Member
  • ****
  • Posts: 302
Re: [SOLVED] Window SDL2 Drop Files
« Reply #16 on: April 23, 2023, 04:36:02 pm »
What is 'VPlayer' ?  Which Player do You use ?

The VLC-Player via Component 'TPasLibVlcPlayer' as suggested here ?
Life could be so easy, if there weren't those f*** Details.
My FFmpeg4Lazarus = FFPlay4Laz + FFGrab4Laz + FFInfo4Laz

Pe3s

  • Hero Member
  • *****
  • Posts: 633
Re: [SOLVED] Window SDL2 Drop Files
« Reply #17 on: April 23, 2023, 04:45:48 pm »
VPlayer is my name, some of the code is from some demo by user somba

metis

  • Sr. Member
  • ****
  • Posts: 302
Re: [SOLVED] Window SDL2 Drop Files
« Reply #18 on: April 23, 2023, 05:14:14 pm »
I think You mean somby and his MediaPlayer.
Why don't You ask him directly here or here ?
Life could be so easy, if there weren't those f*** Details.
My FFmpeg4Lazarus = FFPlay4Laz + FFGrab4Laz + FFInfo4Laz

Pe3s

  • Hero Member
  • *****
  • Posts: 633
Re: [SOLVED] Window SDL2 Drop Files
« Reply #19 on: April 23, 2023, 05:20:32 pm »
I asked but I didn't get an answer, I started a thread, you answered and we're discussing

metis

  • Sr. Member
  • ****
  • Posts: 302
Re: [SOLVED] Window SDL2 Drop Files
« Reply #20 on: April 23, 2023, 05:24:59 pm »
HaHaHa.
Well, ok, but I need much more Details about Your Player.
More Code, please.
Life could be so easy, if there weren't those f*** Details.
My FFmpeg4Lazarus = FFPlay4Laz + FFGrab4Laz + FFInfo4Laz

Pe3s

  • Hero Member
  • *****
  • Posts: 633
Re: [SOLVED] Window SDL2 Drop Files
« Reply #21 on: April 23, 2023, 05:41:26 pm »
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, Buttons, Core,
  9.   LCLIntf, Math, Types, LCLtype;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     ImageList1: TImageList;
  17.     OpenDialog1: TOpenDialog;
  18.     LVideoPosition: TPanel;
  19.     LVideoDuration: TPanel;
  20.     PBottom: TPanel;
  21.     SpeedButton1: TSpeedButton;
  22.     videoSeekBar: TPanel;
  23.     volumeBar: TPanel;
  24.     BOpen: TSpeedButton;
  25.     BPlay: TSpeedButton;
  26.     BPause: TSpeedButton;
  27.     BStop: TSpeedButton;
  28.     btnPrev: TSpeedButton;
  29.     btnNext: TSpeedButton;
  30.     btnVolume: TSpeedButton;
  31.     btnNextFrame: TSpeedButton;
  32.     procedure BOpenClick(Sender: TObject);
  33.     procedure BPauseClick(Sender: TObject);
  34.     procedure BPlayClick(Sender: TObject);
  35.     procedure BStopClick(Sender: TObject);
  36.     procedure btnNextFrameClick(Sender: TObject);
  37.     procedure FormCreate(Sender: TObject);
  38.     procedure FormDestroy(Sender: TObject);
  39.     procedure FormDropFiles(Sender: TObject; const FileNames: array of string);
  40.     procedure FormMouseWheel(Sender: TObject; Shift: TShiftState;
  41.       WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
  42.     procedure SpeedButton1Click(Sender: TObject);
  43.         procedure videoSeekBarMouseDown(Sender: TObject; Button: TMouseButton;
  44.       Shift: TShiftState; X, Y: Integer);
  45.     procedure videoSeekBarPaint(Sender: TObject);
  46.     procedure volumeBarMouseMove(Sender: TObject; Shift: TShiftState; X,
  47.       Y: Integer);
  48.     procedure volumeBarPaint(Sender: TObject);
  49.   private
  50.     procedure UpdateProgress(Sender: TObject);
  51.     procedure OpenVideo(FName: String);
  52.     procedure SetVolume(FVolume: Integer);
  53.  
  54.   public
  55.     FPlayer : TEXPlayer;
  56.     FProgress, videoPosition, volumePosition : Integer;
  57.     videoDuration : Int64;
  58.  
  59.      OriginalBounds: TRect;
  60.     OriginalWindowState: TWindowState;
  61.     ScreenBounds: TRect;
  62.   end;
  63.  
  64. var
  65.   Form1: TForm1;
  66.   seeking: double;
  67.  
  68. implementation
  69.  
  70. {$R *.lfm}
  71.  
  72. { TForm1 }
  73.  
  74. procedure TForm1.UpdateProgress(Sender: TObject);
  75. var
  76.   FPosition, streamPosition, streamDuration, streamStartTime : Double;
  77. begin
  78.   if not FPlayer.Playing then Exit;
  79.  
  80.   streamPosition := FPlayer.StreamPosition;
  81.   streamStartTime := FPlayer.StreamStartTime;
  82.   streamDuration := FPlayer.StreamDuration;
  83.  
  84.   FPosition := streamPosition - streamStartTime;
  85.  
  86.   if (streamDuration > 0) then
  87.   begin
  88.     videoDuration := Trunc(streamDuration * FProgress);
  89.     videoPosition := 0;
  90.  
  91.     LVideoDuration.Caption := FormatDateTime('hh:nn:ss', streamDuration / 86400);
  92.  
  93.     if FPosition >= 0 then
  94.     begin
  95.       LVideoPosition.Caption := FormatDateTime('hh:nn:ss', FPosition / 86400);
  96.       videoPosition := Trunc(FPosition * FProgress);
  97.       videoSeekBar.Invalidate;
  98.     end else
  99.     begin
  100.       LVideoPosition.Caption := '00:00:00';
  101.       videoPosition := 0;
  102.     end;
  103.   end else
  104.   begin
  105.       videoPosition := 0;
  106.       videoDuration := 0;
  107.       LVideoPosition.Caption := '';
  108.       LVideoDuration.Caption := '';
  109.   end;
  110. end;
  111.  
  112. procedure TForm1.OpenVideo(FName: String);
  113. begin
  114.   FPlayer.Stop;
  115.   FPlayer.Url := FName;
  116.   Form1.Caption := ExtractFileName(FName);
  117.   FPlayer.Play;
  118.  
  119.   FPlayer.AudioVolume := volumePosition;
  120. end;
  121.  
  122. procedure TForm1.SetVolume(FVolume: Integer);
  123. begin
  124.   if FVolume < 0 then
  125.   volumePosition := 0
  126.   else if FVolume > 100 then
  127.   volumePosition := 100;
  128.  
  129.   FPlayer.AudioVolume := FVolume;
  130.  
  131.   case (FVolume) of
  132.        51..100: btnVolume.ImageIndex := 7;
  133.          1..50: btnVolume.ImageIndex := 8;
  134.              0: btnVolume.ImageIndex := 9;
  135.     end;
  136. end;
  137.  
  138. procedure TForm1.FormCreate(Sender: TObject);
  139. begin
  140.   volumePosition := 100;
  141.   videoPosition := 0;
  142.   videoDuration := 100;
  143.   FProgress := 1000;
  144.  
  145.   FPlayer := TEXPlayer.Create(nil);
  146.   with FPlayer do
  147.     begin
  148.         Align := alClient;
  149.         OnProgress := @Self.UpdateProgress;
  150.         Parent := Self;
  151.     end;
  152. end;
  153.  
  154. procedure TForm1.FormDestroy(Sender: TObject);
  155. begin
  156.   FreeAndNil(FPlayer);
  157. end;
  158.  
  159. procedure TForm1.FormDropFiles(Sender: TObject; const FileNames: array of string);
  160. begin
  161.   OpenVideo(FileNames[0]);
  162. end;
  163.  
  164. procedure TForm1.FormMouseWheel(Sender: TObject; Shift: TShiftState;
  165.   WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
  166. begin
  167.   volumePosition := volumePosition + EnsureRange(WheelDelta, -4, 4);
  168.   volumeBar.Invalidate;
  169.  
  170.   SetVolume(volumePosition);
  171. end;
  172.  
  173. procedure TForm1.SpeedButton1Click(Sender: TObject);
  174. var
  175.   png: TCustomBitmap;
  176. begin
  177.   ImageList1.Clear;
  178.   ImageList1.Width:= 32;
  179.   ImageList1.Height:= 32;
  180.   png := TPortableNetworkGraphic.Create;
  181.   try
  182.     png.LoadFromFile(Application.Location + 'pasek.png');
  183.     ImageList1.AddSliced(png, 11, 1);
  184.   finally
  185.   png.Free;
  186.   end;
  187. end;
  188.  
  189. procedure TForm1.BOpenClick(Sender: TObject);
  190. begin
  191.   if not OpenDialog1.Execute then Exit;
  192.   OpenVideo(OpenDialog1.FileName);
  193. end;
  194.  
  195. procedure TForm1.videoSeekBarMouseDown(Sender: TObject; Button: TMouseButton;
  196.   Shift: TShiftState; X, Y: Integer);
  197. begin
  198.   if (ssLeft in Shift) then
  199.   begin
  200.     FPlayer.Seek((X * videoDuration) div videoSeekBar.Width / FProgress, false);
  201.   end;
  202. end;
  203.  
  204. procedure TForm1.videoSeekBarPaint(Sender: TObject);
  205. var
  206.   R : TRect;
  207. begin
  208.   with videoSeekBar, Canvas do
  209.   begin
  210.     Brush.Color := clWhite;
  211.     //Pen.Color := RGB(58, 40, 76);
  212.     //Rectangle(0, 0, videoSeekBar.Width, videoSeekBar.Height);
  213.     R := Rect(0, 0, videoSeekBar.Width * videoPosition div videoDuration, videoSeekBar.Height);
  214.     Brush.Color := RGB(48, 48, 48);
  215.     FillRect(R);
  216.   end;
  217. end;
  218.  
  219. procedure TForm1.volumeBarMouseMove(Sender: TObject; Shift: TShiftState; X,
  220.   Y: Integer);
  221. begin
  222.   if (ssLeft in Shift) then
  223.   begin
  224.     volumePosition := Round(X * 100 / volumeBar.Width);
  225.     volumeBar.Invalidate;
  226.  
  227.     SetVolume(volumePosition);
  228.   end;
  229. end;
  230.  
  231. procedure TForm1.volumeBarPaint(Sender: TObject);
  232. var
  233.   R : TRect;
  234. begin
  235.   with volumeBar, Canvas do
  236.   begin
  237.     Brush.Color := clWhite;
  238.     Pen.Color := RGB(58, 40, 76);
  239.     Rectangle(0, 0, volumeBar.Width, volumeBar.Height);
  240.     R := Rect(1, 1, volumeBar.Width * volumePosition div 100, volumeBar.Height -1);
  241.     Brush.Color := RGB(58, 40, 76);
  242.     FillRect(R);
  243.   end;
  244. end;
  245.  
  246. procedure TForm1.BPlayClick(Sender: TObject);
  247. begin
  248.   if not FPlayer.Playing then
  249.   begin
  250.     FPlayer.Play;
  251.   end else
  252.   begin
  253.     FPlayer.Resume;
  254.   end;
  255.   if not FPlayer.Playing then ShowMessage('Brak pliku do odtworzenia');
  256.   Exit;
  257. end;
  258.  
  259. procedure TForm1.BPauseClick(Sender: TObject);
  260. begin
  261.   FPlayer.Pause;
  262. end;
  263.  
  264. procedure TForm1.BStopClick(Sender: TObject);
  265. begin
  266.   FPlayer.Stop;
  267.   videoPosition := 0;
  268.   videoSeekBar.Invalidate;
  269. end;
  270.  
  271. procedure TForm1.btnNextFrameClick(Sender: TObject);
  272. begin
  273.   if BorderStyle <> bsNone then begin
  274.       // To full screen
  275.       OriginalWindowState := WindowState;
  276.       OriginalBounds := BoundsRect;
  277.  
  278.       BorderStyle := bsNone;
  279.       BoundsRect := Screen.MonitorFromWindow(Handle).BoundsRect;
  280.  
  281.     end else begin
  282.       // From full screen
  283.       BorderStyle := bsSizeable;
  284.       if OriginalWindowState = wsMaximized then
  285.         WindowState := wsMaximized
  286.       else
  287.         BoundsRect := OriginalBounds;
  288.     end;
  289. end;
  290.  
  291. end.
  292.  
  293.  

Pe3s

  • Hero Member
  • *****
  • Posts: 633
Re: [SOLVED] Window SDL2 Drop Files
« Reply #22 on: April 23, 2023, 05:48:21 pm »
@Somby's project is a good demo for me to learn SDL all tutorials are in C++ which I don't know. That's why I chose him.


metis

  • Sr. Member
  • ****
  • Posts: 302
Re: [SOLVED] Window SDL2 Drop Files
« Reply #23 on: April 23, 2023, 07:18:17 pm »
Quote
... a good demo for me to learn SDL all tutorials are in C++ ...
Nope - Here is SDL in pure FPC, how it's done and learn, how it's done:
https://forum.lazarus.freepascal.org/index.php/topic,42698.msg376204.html#msg376204
• My FFPlay4Laz-MinimalPlayers are also SDL-Tutorials, for SDL1 and for SDL2
'Free Pascal meets SDL' has very good Tutorials for SDL-Beginners.

But I still don't know anything about the Player itself, I mean that what You've named 'FPlayer',
in particular, how You pass the URL/MRL to your Player, which is apparently in Unit 'Core'.
« Last Edit: April 23, 2023, 07:37:59 pm by metis »
Life could be so easy, if there weren't those f*** Details.
My FFmpeg4Lazarus = FFPlay4Laz + FFGrab4Laz + FFInfo4Laz

Pe3s

  • Hero Member
  • *****
  • Posts: 633
Re: [SOLVED] Window SDL2 Drop Files
« Reply #24 on: April 23, 2023, 07:41:03 pm »
I read about SDL, I read your project code.

metis

  • Sr. Member
  • ****
  • Posts: 302
Re: [SOLVED] Window SDL2 Drop Files
« Reply #25 on: April 24, 2023, 01:07:31 pm »
At first Glance, You're 'core.pas' is (based on) Somby's Unit 'uexplayer.pas' from the 'SombysSources.zip', which can be downloaded here
-> GoTo "Quellen aller Anwendungen".
(Somby's WebSite obviously only exists in German, couldn't find an English Version.)

The URL(STRING) is passed to FFmpeg at Line #2692:
ret := avformat_open_input(@FFormatCtx, PChar(FUrl), nil, @FFormatOpts);
which is o.k.

Which FFmpeg- and SDL-Versions do You use ?
Why don't You use Somby's Player as is ?
Life could be so easy, if there weren't those f*** Details.
My FFmpeg4Lazarus = FFPlay4Laz + FFGrab4Laz + FFInfo4Laz

Pe3s

  • Hero Member
  • *****
  • Posts: 633
Re: [SOLVED] Window SDL2 Drop Files
« Reply #26 on: April 24, 2023, 04:37:36 pm »
@Somba's player was missing file drop and I wanted to do my GUI.
And as I wrote earlier, I used this player to learn SDL. I have never written anywhere before that the player's code is my own.


metis

  • Sr. Member
  • ****
  • Posts: 302
Re: [SOLVED] Window SDL2 Drop Files
« Reply #27 on: April 24, 2023, 09:57:52 pm »
Quote
I have never written anywhere before that the player's code is my own.
Never said, that You did.
Actually, Somby's 'uexplayer.pas' is more than heavily based on FFmpeg's TestPlayer FFplay.

Quote
... C++ which I don't know.
Well, now You have a good Opportunity to learn C++ by simply Comparing (big) Parts of Somby's 'uexplayer.pas' with FFmpeg's ffplay.c:D

Quote
Somba's player was missing file drop ...
Simply do in 'FormDropFiles()' the same, what Somby does via the DialogBox to open a MRL/URL - That should work.  ;)
« Last Edit: April 24, 2023, 10:01:29 pm by metis »
Life could be so easy, if there weren't those f*** Details.
My FFmpeg4Lazarus = FFPlay4Laz + FFGrab4Laz + FFInfo4Laz

Pe3s

  • Hero Member
  • *****
  • Posts: 633
Re: [SOLVED] Window SDL2 Drop Files
« Reply #28 on: April 25, 2023, 07:35:46 am »
FormDropFiles doesn't work

metis

  • Sr. Member
  • ****
  • Posts: 302
Re: [SOLVED] Window SDL2 Drop Files
« Reply #29 on: April 25, 2023, 03:44:04 pm »
Does Somby's Player work at all ?
Can You open anything via the DialogBox ?
Life could be so easy, if there weren't those f*** Details.
My FFmpeg4Lazarus = FFPlay4Laz + FFGrab4Laz + FFInfo4Laz

 

TinyPortal © 2005-2018