Difference between revisions of "ActiveX/Delphi"

From VideoLAN Wiki
Jump to navigation Jump to search
 
 
(22 intermediate revisions by 10 users not shown)
Line 1: Line 1:
To be edited a lot...
+
{{See also|Using libvlc with Delphi}}
 +
{{howto| use the [[ActiveX]] control with Delphi|nosort=yes}} 
  
How to use VLC within your own Delphi Application:
+
==Getting started==
Components --> Import ActiveX --> VideoLan Client
+
===What you need===
Create a new Package and select "Install".
+
* Borland Delphi 3 or newer
 +
* a running System with Microsoft Windows
 +
* [http://www.videolan.org/ The VideoLan Client] (VLC) including the [[ActiveX]] Plugin installed
  
The VLC-Player Object can be found in your ActiveX-Components Tabsheet.
+
===Import the ActiveX-Component===
Place one of it in your Form1, place a TButton and use the following code:
+
*Start your Borland Delphi
 +
*< Delphi2005: Select Components --> Import ActiveX --> VideoLan VLC ActiveX Plugin
 +
*>= Delphi 2006: Select Components --> Import component --> Import ActiveX Control --> VideoLan VLC ActiveX Plugin
 +
*Otherwise try creating a new package using the created ''AXVLC_TLB.pas''
  
unit Unit1;
+
===Confirm successfull installation===
 +
*You should now be able to add the ''TVLCPlugin'' from the ActiveX-Tab of your Component toolbox.
  
interface
+
==Usage Development-Time==
 
+
The VLC-Player Object ''TVLCPlugin'' can be found in your ActiveX-Components Tabsheet.
uses
+
Place one of it in your Form1, place a TButton and use the following code:
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
+
<big><big><syntaxhighlight lang="delphi">
  Dialogs, StdCtrls, OleCtrls, AXVLC_TLB;
+
unit Unit1;
 
+
type
+
interface
  TForm1 = class(TForm)
+
    Button1: TButton;
+
uses
    vlc: TVLCPlugin;
+
  Windows, Variants, Forms, Classes, Controls, StdCtrls, OleCtrls,
    procedure Button1Click(Sender: TObject);
+
  AXVLC_TLB;
  private
+
    { Private-Deklarationen }
+
type
  public
+
  TForm1 = class(TForm)
    { Public-Deklarationen }
+
    VLCPlugin1: TVLCPlugin;
  end;
+
    Button1: TButton;
 
+
    procedure Button1Click(Sender: TObject);
type
+
  private
VLCPlaylistMode = TOleEnum;
+
    { Private-Deklarationen }
const
+
  public
VLCPlayListInsert = $00000001;
+
    { Public-Deklarationen }
VLCPlayListReplace = $00000002;
+
  end;
VLCPlayListAppend = $00000004;
+
VLCPlayListGo = $00000008;
+
type
VLCPlayListCheckInsert = $00000010;  
+
  VLCPlaylistMode = TOleEnum;
 
+
var
+
const
  Form1: TForm1;
+
  VLCPlayListInsert     = $00000001;
 +
  VLCPlayListReplace     = $00000002;
 +
  VLCPlayListAppend     = $00000004;
 +
  VLCPlayListGo         = $00000008;
 +
  VLCPlayListCheckInsert = $00000010;
 +
 +
var
 +
  Form1: TForm1;
 +
 +
implementation
 +
 +
{$R *.dfm}
 +
 +
procedure TForm1.Button1Click(Sender: TObject);
 +
begin
 +
  VLCPlugin1.addTarget('C:\video.mpg', null, VLCPlayListInsert, 0);
 +
  // you can use any MRL with parameters instead of 'c:\video.mpg' here
 +
  VLCPlugin1.play;
 +
end;
 +
 +
end.
 +
</syntaxhighlight></big></big>
  
implementation
+
==Usage Runtime==
 +
If you're planning to use the VLC-Player in your application but don't know when and where, use this code to create the component on-demand.
  
{$R *.dfm}
+
<big><big><syntaxhighlight lang="delphi">
 +
unit Unit1;
 +
 +
interface
 +
 +
uses
 +
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, OleCtrls,
 +
  AXVLC_TLB, StdCtrls, Registry, Dialogs;
 +
 +
type
 +
  TForm1 = class(TForm)
 +
    Button1: TButton;
 +
    Button2: TButton;
 +
    procedure Button2Click(Sender: TObject);
 +
    procedure Button1Click(Sender: TObject);
 +
  private
 +
    { Private-Deklarationen }
 +
  public
 +
    { Public-Deklarationen }
 +
  end;
 +
 +
var
 +
  Form1: TForm1;
 +
  VLCPlugin1: TVLCPlugin;
 +
  blVLCPluginFound: boolean;
 +
 +
type
 +
  VLCPlaylistMode = TOleEnum;
 +
 +
const
 +
  VLCPlayListInsert      = $00000001;
 +
  VLCPlayListReplace    = $00000002;
 +
  VLCPlayListAppend      = $00000004;
 +
  VLCPlayListGo          = $00000008;
 +
  VLCPlayListCheckInsert = $00000010;
 +
 +
implementation
 +
 +
{$R *.dfm}
 +
 +
procedure TForm1.Button1Click(Sender: TObject);
 +
var
 +
  Reg: TRegistry;
 +
begin
 +
  blVLCPluginFound := false;
 +
 +
  // Is VLC ActiveX Plugin installed on this PC?
 +
  Reg := TRegistry.Create;
 +
  try
 +
    Reg.RootKey := HKEY_LOCAL_MACHINE;
 +
    if Reg.OpenKeyReadOnly('\Software\Classes\VideoLAN.VLCPlugin.1\') then begin
 +
        blVLCPluginFound := true;
 +
    end;
 +
  finally
 +
    FreeAndNil(Reg);
 +
  end;
 +
 +
  if blVLCPluginFound then begin
 +
    VLCPlugin1 := TVLCPlugin.Create(Self);
 +
    VLCPlugin1.Parent := Self; // Means: Place the VLC-Player into Form1
 +
    VLCPlugin1.Width  := 400;
 +
    VLCPlugin1.Height := 300;
 +
    VLCPlugin1.Top  := 50;
 +
    VLCPlugin1.Left := 50;
 +
    VLCPlugin1.Show;
 +
    VLCPlugin1.addTarget('C:\video.mpg', null, VLCPlayListInsert, 0);
 +
    // you can use any MRL with parameters instead of 'c:\video.mpg' here
 +
    VLCPlugin1.play;
 +
  end else begin
 +
    ShowMessage('I am really sorry, but VLC (or its ActiveX Plugin) is currently not installed on this PC!');
 +
  end;
 +
end;
 +
 +
procedure TForm1.Button2Click(Sender: TObject);
 +
begin
 +
  if blVLCPluginFound then begin
 +
    VLCPlugin1.stop;
 +
    FreeAndNil(VLCPlugin1);
 +
  end;
 +
end;
 +
 +
end.
 +
</syntaxhighlight></big></big>
  
procedure TForm1.Button1Click(Sender: TObject);
+
==Alternative way to bring VLC to your Delphi Application==
begin
+
Much easier way to bring VLC to your Delphi Application is to paste a TWebbrowser Object in your Form, is generate Code for the HTML and m3u file and let the Webbrowser load the HTML-file. For detailed information have a look at [[ActiveX/HTML]].
vlc.addTarget('C:\video.mpg', null, VLCPlayListInsert, 0);
 
// you can use any MRL with parameters instead of 'c:\video.mpg' here
 
vlc.play;
 
  
end;
+
You can also use [[LibVLC]] like in [http://tothpaul.free.fr/sources.php?dprgrp.vld VideoLAN for Delphi].
  
end.
+
==See also==
 +
[[ActiveX/HTML]]

Latest revision as of 09:07, 19 March 2019

This page describes how to use the ActiveX control with Delphi. Other "how to" pages

Getting started

What you need

  • Borland Delphi 3 or newer
  • a running System with Microsoft Windows
  • The VideoLan Client (VLC) including the ActiveX Plugin installed

Import the ActiveX-Component

  • Start your Borland Delphi
  • < Delphi2005: Select Components --> Import ActiveX --> VideoLan VLC ActiveX Plugin
  • >= Delphi 2006: Select Components --> Import component --> Import ActiveX Control --> VideoLan VLC ActiveX Plugin
  • Otherwise try creating a new package using the created AXVLC_TLB.pas

Confirm successfull installation

  • You should now be able to add the TVLCPlugin from the ActiveX-Tab of your Component toolbox.

Usage Development-Time

The VLC-Player Object TVLCPlugin can be found in your ActiveX-Components Tabsheet. Place one of it in your Form1, place a TButton and use the following code:

 unit Unit1;
 
 interface
 
 uses
   Windows, Variants, Forms, Classes, Controls, StdCtrls, OleCtrls,
   AXVLC_TLB;
 
 type
   TForm1 = class(TForm)
     VLCPlugin1: TVLCPlugin;
     Button1: TButton;
     procedure Button1Click(Sender: TObject);
   private
     { Private-Deklarationen }
   public
     { Public-Deklarationen }
   end;
 
 type
   VLCPlaylistMode = TOleEnum;
 
 const
   VLCPlayListInsert      = $00000001;
   VLCPlayListReplace     = $00000002;
   VLCPlayListAppend      = $00000004;
   VLCPlayListGo          = $00000008;
   VLCPlayListCheckInsert = $00000010;
 
 var
   Form1: TForm1;
 
 implementation
 
 {$R *.dfm}
 
 procedure TForm1.Button1Click(Sender: TObject);
 begin
   VLCPlugin1.addTarget('C:\video.mpg', null, VLCPlayListInsert, 0);
   // you can use any MRL with parameters instead of 'c:\video.mpg' here
   VLCPlugin1.play;
 end;
 
 end.

Usage Runtime

If you're planning to use the VLC-Player in your application but don't know when and where, use this code to create the component on-demand.

 unit Unit1;
 
 interface
 
 uses
   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, OleCtrls,
   AXVLC_TLB, StdCtrls, Registry, Dialogs;
 
 type
   TForm1 = class(TForm)
     Button1: TButton;
     Button2: TButton;
     procedure Button2Click(Sender: TObject);
     procedure Button1Click(Sender: TObject);
   private
     { Private-Deklarationen }
   public
     { Public-Deklarationen }
   end;
 
 var
   Form1: TForm1;
   VLCPlugin1: TVLCPlugin;
   blVLCPluginFound: boolean;
 
 type
   VLCPlaylistMode = TOleEnum;
 
 const
   VLCPlayListInsert      = $00000001;
   VLCPlayListReplace     = $00000002;
   VLCPlayListAppend      = $00000004;
   VLCPlayListGo          = $00000008;
   VLCPlayListCheckInsert = $00000010;
 
 implementation
 
 {$R *.dfm}
 
 procedure TForm1.Button1Click(Sender: TObject);
 var
   Reg: TRegistry;
 begin
   blVLCPluginFound := false;
 
   // Is VLC ActiveX Plugin installed on this PC?
   Reg := TRegistry.Create;
   try
     Reg.RootKey := HKEY_LOCAL_MACHINE;
     if Reg.OpenKeyReadOnly('\Software\Classes\VideoLAN.VLCPlugin.1\') then begin
         blVLCPluginFound := true;
     end;
   finally
     FreeAndNil(Reg);
   end;
 
   if blVLCPluginFound then begin
     VLCPlugin1 := TVLCPlugin.Create(Self);
     VLCPlugin1.Parent := Self; // Means: Place the VLC-Player into Form1
     VLCPlugin1.Width  := 400;
     VLCPlugin1.Height := 300;
     VLCPlugin1.Top  := 50;
     VLCPlugin1.Left := 50;
     VLCPlugin1.Show;
     VLCPlugin1.addTarget('C:\video.mpg', null, VLCPlayListInsert, 0);
     // you can use any MRL with parameters instead of 'c:\video.mpg' here
     VLCPlugin1.play;
   end else begin
     ShowMessage('I am really sorry, but VLC (or its ActiveX Plugin) is currently not installed on this PC!');
   end;
 end;
 
 procedure TForm1.Button2Click(Sender: TObject);
 begin
   if blVLCPluginFound then begin
     VLCPlugin1.stop;
     FreeAndNil(VLCPlugin1);
   end;
 end;
 
 end.

Alternative way to bring VLC to your Delphi Application

Much easier way to bring VLC to your Delphi Application is to paste a TWebbrowser Object in your Form, is generate Code for the HTML and m3u file and let the Webbrowser load the HTML-file. For detailed information have a look at ActiveX/HTML.

You can also use LibVLC like in VideoLAN for Delphi.

See also

ActiveX/HTML