Media Player with VLC ActiveX Type library Delphi tutorial (Tip for 10 )


This is an example of media player created in Delphi using VLC multimedia player ActiveX library.

For this to work VLC player and its ActiveX library must be installed.
https://www.videolan.org/vlc/

Then it is necessary to import ActiveX component in Delphi.

Detailed instruction can be seen in this video :


Fallowing is source code for this example :





(code style formatted by http://hilite.me/ )





unit MainForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, OleCtrls, AXVLC_TLB;

type
  TfrmMain = class(TForm)
    VLCPlugin21: TVLCPlugin2;
    ListBox1: TListBox;
    Panel1: TPanel;
    Splitter1: TSplitter;
    Button1: TButton;
    Button2: TButton;
    OpenDialog1: TOpenDialog;
    Edit1: TEdit;
    Button3: TButton;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure ListBox1DblClick(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmMain: TfrmMain;

implementation

{$R *.dfm}

procedure TfrmMain.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute() then
begin
VLCPlugin21.playlist.stop;
VLCPlugin21.playlist.clear;
ListBox1.Items.Clear;
ListBox1.Items.AddStrings(OpenDialog1.Files);
end;
end;

procedure TfrmMain.Button2Click(Sender: TObject);
var
fnamePr:WideString;
fname:WideString;
id:Integer;
begin
if ListBox1.SelCount<>0 then //if sellection is different than zero
begin
fnamePr:='file:///';   //For local files we have to add this in the prefix of file name
fname:=ListBox1.Items[ListBox1.ItemIndex];
fname:=StringReplace(fname,'/','\\',[rfReplaceAll]) ;//we have to replace right
//slashes with two left
fname:=fnamePr+fname; //combine these to strings to file name
Label1.Caption:=fname;
VLCPlugin21.playlist.stop; //stop playback
VLCPlugin21.playlist.clear;//clear playlist.You don't need to do this, you can just
//add new files to the playlist.
//For the sake of simplicity I am doing this way.
id:=VLCPlugin21.playlist.add(PChar(fname),null,null);
VLCPlugin21.playlist.playItem(id);
end;
end;

procedure TfrmMain.Button3Click(Sender: TObject);
var id:Integer;
begin
VLCPlugin21.playlist.stop;
VLCPlugin21.playlist.clear;
id:=VLCPlugin21.playlist.add(PChar(Edit1.Text),null,null);
VLCPlugin21.playlist.playItem(id);
end;

procedure TfrmMain.ListBox1DblClick(Sender: TObject);
begin
Button2.Click;
end;

end.
Share on Google Plus

About Clear SoftX

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.