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;
Thank you. BobaL