How set the window handle with Delphi ?

This forum is about all development around libVLC.
BobaL
New Cone
New Cone
Posts: 8
Joined: 01 Dec 2009 17:40

How set the window handle with Delphi ?

Postby BobaL » 07 Dec 2009 16:18

Hi,

I try to set a correct handle to libvlc dll but the video display never appears...
Could someone help me ?

Here is my code

Code: Select all

unit uVlc; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls; type PException = ^Vlc_Exception; Vlc_Exception = record Code : Integer; Msg : PChar; end; TFormVlc = class(TForm) btPlay: TButton; btStop: TButton; pnVideo: TPanel; MemoLog: TMemo; Filename: TEdit; procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure btPlayClick(Sender: TObject); private Vlc_Dll : THandle; Vlc_Instance : Pointer; Vlc_Player : Pointer; Vlc_Media : Pointer; Vlc_Except : Vlc_Exception; public { Déclarations publiques } end; var FormVlc: TFormVlc; libvlc_new : function (Argc: Integer; Args: PPChar; Exception: Pointer): Pointer; cdecl; libvlc_get_version : function (): PChar; cdecl; libvlc_free : procedure(); cdecl; libvlc_media_player_new : function (Vlc: Pointer; Exception: PException): Pointer; cdecl; libvlc_media_new : function (Vlc: Pointer; const Mrl: PChar; Exception: PException): Pointer; cdecl; libvlc_media_new_as_node : function (Vlc: Pointer; const Name: PChar; Exception: PException): Pointer; cdecl; libvlc_media_player_get_hwnd : function (Player: Pointer): Pointer; cdecl; libvlc_media_player_set_hwnd : procedure(Player: Pointer; VideoOwner: Pointer; Exception: PException); cdecl; libvlc_media_player_set_media : procedure(Player: Pointer; Media: Pointer; Exception: PException); cdecl; libvlc_media_player_get_media : function (Player: Pointer; Exception: PException): Pointer; cdecl; libvlc_media_player_is_playing : function (Player: Pointer; Exception: PException): Integer; cdecl; libvlc_media_player_play : procedure(Media: Pointer; Exception: PException); cdecl; libvlc_media_player_stop : procedure(Media: Pointer; Exception: PException); cdecl; implementation uses uVideo; {$R *.dfm} //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ procedure TFormVlc.FormCreate(Sender: TObject); begin // end; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ procedure TFormVlc.FormDestroy(Sender: TObject); begin if Assigned(Vlc_Instance) and Assigned(libvlc_free) then libvlc_free; if Vlc_Dll >= 32 then FreeLibrary(Vlc_Dll); end; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ procedure TFormVlc.btPlayClick(Sender: TObject); var MyHandle: HWND; Args: array [0..1] of PChar; begin try if not FileExists(Filename.Text) then begin Vlc_Dll := LoadLibrary(PChar('libvlc.dll')); if Vlc_Dll >= 32 then begin @libvlc_new := GetProcAddress(Vlc_Dll, 'libvlc_new'); @libvlc_get_version := GetProcAddress(Vlc_Dll, 'libvlc_get_version'); @libvlc_free := GetProcAddress(Vlc_Dll, 'libvlc_free'); @libvlc_media_player_new := GetProcAddress(Vlc_Dll, 'libvlc_media_player_new'); @libvlc_media_new := GetProcAddress(Vlc_Dll, 'libvlc_media_new'); @libvlc_media_new_as_node := GetProcAddress(Vlc_Dll, 'libvlc_media_new_as_node'); @libvlc_media_player_get_hwnd := GetProcAddress(Vlc_Dll, 'libvlc_media_player_get_hwnd'); @libvlc_media_player_set_hwnd := GetProcAddress(Vlc_Dll, 'libvlc_media_player_set_hwnd'); @libvlc_media_player_set_media := GetProcAddress(Vlc_Dll, 'libvlc_media_player_set_media'); @libvlc_media_player_get_media := GetProcAddress(Vlc_Dll, 'libvlc_media_player_get_media'); @libvlc_media_player_is_playing := GetProcAddress(Vlc_Dll, 'libvlc_media_player_is_playing'); @libvlc_media_player_play := GetProcAddress(Vlc_Dll, 'libvlc_media_player_play'); @libvlc_media_player_stop := GetProcAddress(Vlc_Dll, 'libvlc_media_player_stop'); if Assigned(libvlc_new) then begin Args[0] := nil; Vlc_Instance := libvlc_new(0, @Args[0], @Vlc_Except); if (Vlc_Except.Code = 0) and Assigned(Vlc_Instance) and Assigned(libvlc_get_version) then begin MemoLog.Lines.Add(libvlc_get_version); if (Vlc_Except.Code = 0) and Assigned(libvlc_media_player_new) then begin Vlc_Player := libvlc_media_player_new(Vlc_Instance, @Vlc_Except); if (Vlc_Except.Code = 0) and Assigned(Vlc_Player) and Assigned(libvlc_media_player_set_hwnd) then begin FormVideo.Show; MyHandle := FormVideo.Handle; libvlc_media_player_set_hwnd(Vlc_Player, @MyHandle, @Vlc_Except); if (Vlc_Except.Code = 0) and Assigned(libvlc_media_new) then begin Vlc_Media := libvlc_media_new(Vlc_Instance, PChar('C:\0.avi'), @Vlc_Except); if (Vlc_Except.Code = 0) and Assigned(Vlc_Media) and Assigned(libvlc_media_player_set_media) then begin libvlc_media_player_set_media(Vlc_Player, Vlc_Media, @Vlc_Except); libvlc_media_player_get_media(Vlc_Player, @Vlc_Except); if (Vlc_Except.Code = 0) and Assigned(libvlc_media_player_play) and Assigned(libvlc_media_player_is_playing) then begin MemoLog.Lines.Add(IntToStr(libvlc_media_player_is_playing(Vlc_Player, @Vlc_Except))); libvlc_media_player_play(Vlc_Media, @Vlc_Except); MemoLog.Lines.Add(IntToStr(libvlc_media_player_is_playing(Vlc_Player, @Vlc_Except))); end; end; end; end; end; end; end; end; end else ShowMessage('File not exists'); except on E: Exception do ShowMessage(E.Message); end; end;
I think my exception declaration is wrong but I don't know how done it...

Thank you. BobaL

desp
Blank Cone
Blank Cone
Posts: 11
Joined: 20 May 2009 11:59

Re: How set the window handle with Delphi ?

Postby desp » 10 Dec 2009 12:25

You don't need to declare exception record, just VLC_Exception = pointer; and remember allways use var in libvlc_some_function(.....; var exception : VLC_Exception);

To set windows handle, use libvlc_media_player_set_drawable() function, create panel and give his .Handle property.

.. and also check if u set up correct plugins directory path :)

BobaL
New Cone
New Cone
Posts: 8
Joined: 01 Dec 2009 17:40

Re: How set the window handle with Delphi ?

Postby BobaL » 10 Dec 2009 15:28

Hi desp,

Thank you for your help...
I try to use the last libvlc api version and libvlc_media_player_set_drawable() function is not available on it (Goldeneye 1.0.1).
I hope someone arrived to render a video file into a Delphi panel and will explain us how to do... :oops:

For the moment i made this

Code: Select all

MyHandle := pnVideo.Handle; libvlc_media_player_set_hwnd(Vlc_Player, @MyHandle, @Vlc_Except);
But nothing appear in my panel...

Any idea ?

desp
Blank Cone
Blank Cone
Posts: 11
Joined: 20 May 2009 11:59

Re: How set the window handle with Delphi ?

Postby desp » 10 Dec 2009 18:24

I suggest u to use search on this forum and u will find Delphi 0.8.6 wrapper.. Download latest vlc and copy dlls and plugins. :)


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 2 guests