Using the VLC ActiveX control in WPF

How to integrate the powerful VLC media player into your WPF application

Prerequisites:

  • Windows version of VLC Media Player with the ActiveX component installed.
  • Microsoft Visual Studio 2010 professional / Microsoft Visual C# 2010 Express (Don’t know if this method works on older versions).

Instructions:

  1. If you are not adding this to a current project then create a Visual C# > Windows > WPF Application.
  2. Add a User Control to your project (Project > Add New Item > Visual C# > User Control).
  3. Open the Toolbox (if you can’t see this: View > Toolbox).
  4. Right Click anywhere on the Toolbox then click on Choose Items. (This may take a while to open)
  5. Navigate to the COM Components tab, find and check “VideoLAN VLC ActiveX plugin v1” (axvlc.dell) and press OK.
  6. Now in your Toolbox you should see “VideoLAN VLC ActiveX plugin v1”. Double click on it and set its Dock Property to “Fill”
  7. Now save an build your project (Build > Build Solution.. or press F6)
  8. In the Solution Explorer under References you should now see “AXVLC” and “AxAXVLC”. if you don’t add them manually by right clicking on References, go into your projects debug folder and add “AxInterop.AXVLC.dll” and “Interop.AXVLC.dll”.
  9. Right clicking on References in the Solution Explorer, then Add Reference; Browse to the .NET Tab and find and select “WindowsFormsIntegration”, then press OK.
  10. Now in MainWindow.xaml (or where ever you want to add it to), Add a name to your grid (or the container)… i named mine “grid1”.
  11. From the toolbox add a WindowsFormsHost to the grid, and name it. I named mine “WFH1”  (see Figure 1)
  12. Now right click on your main window and click on View Code.
  13. Declare “AxAXVLC.AxVLCPlugin” as a global variable. (AxAXVLC.AxVLCPlugin vlcPlayer = new AxAXVLC.AxVLCPlugin();
  14. in your default constructor add the player object as the child of the WindowsFormsHost (WFH1.Child = vlcPlayer;)
  15. And that’s it! you wont see anything when you run the program, but the player is there, i will post a code snippet below so you can get a file to open and play in it (Figure 2).
  16. See http://wiki.videolan.org/ActiveX for instructions on how to use the VLC media player ActiveX Plugin.

UPDATE 16-OCT-2011: (List of Fields/Methods/Events of the Plug-in)
Here are a list of fields/methods/events that should allow you to have a lot of control over the plug-in:
Fields

  • bool AutoLoop { get; set; }
  • bool AutoPlay { get; set; }
  • bool CtlVisible { get; set; }
  • int Length { get; }
  • string MRL { get; set; }
  • bool Playing { get; }
  • int PlaylistCount { get; }
  • int PlaylistIndex { get; }
  • float Position { get; set; }
  • int Time { get; set; }
  • string VersionInfo { get; }
  • int Volume { get; set; }

Events

  • MediaPlayerBackward;
  • MediaPlayerBuffering;
  • MediaPlayerEncounteredError;
  • MediaPlayerEndReached;
  • MediaPlayerForward;
  • MediaPlayerNothingSpecial;
  • MediaPlayerOpening;
  • MediaPlayerPausableChanged;
  • MediaPlayerPaused;
  • MediaPlayerPlaying;
  • MediaPlayerPositionChanged;
  • MediaPlayerSeekableChanged;
  • MediaPlayerStopped;
  • MediaPlayerTimeChanged;
  • pauseEvent;
  • playEvent;
  • stopEvent;

Methods

  • void addTarget(string uri, object options, VLCPlaylistMode mode, int position);
  • void AttachInterfaces();
  • void CreateSink();
  • void DetachSink();
  • void fullscreen();
  • object getVariable(string name);
  • void pause();
  • void play();
  • void playFaster();
  • void playlistClear();
  • void playlistNext();
  • void playlistPrev();
  • void playSlower();
  • void setVariable(string name, object value);
  • void shuttle(int seconds);
  • void stop();
  • void toggleMute();
Figuare 1

Example of further useage:

I just added a button to my application to open allow the user to select a file and play it in the player:

[Updated 08 Oct 2012, courtesy of bielb89 from YouTube]

VLC V2.x.x.x +You will need to add “file:///” +before the Url for the file.

Figure 2.. Click on the more button to see a written version of the code.. [This Picture is outdated]
using System.Windows;
using System.Windows.Forms;

namespace WPFVLC
{
    ///
<summary> /// Interaction logic for MainWindow.xaml
 /// </summary>
    public partial class MainWindow : Window
    {
        AxAXVLC.AxVLCPlugin vlcPlayer = new AxAXVLC.AxVLCPlugin();
        public MainWindow()
        {
            InitializeComponent();
            WFH1.Child = vlcPlayer;
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            string mrl = "";
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.ShowDialog();
            if (ofd.FileName != "")
            {
                mrl = ofd.FileName;
                vlcPlayer.addTarget("file:///" +mrl, null, AXVLC.VLCPlaylistMode.VLCPlayListReplaceAndGo, 0);
                vlcPlayer.play();
            }
        }
    }
}

AdvancedPostIt devlopment update

Progress of this project is moving much faster than i first expected.

I use what i call “Development Versions”(DevV)  to track progress on my project, DevV’s are just backups i make of the project before adding/changing large amounts of code.

Here is the progress I’ve made on the project recently:

Continue reading “AdvancedPostIt devlopment update”

Something i’m working on..

A few weeks ago i started working on a application that i can use when working/doing assignments. The idea behind the program is simple, i needed something that can display information/pictures/videos, and will stay on top of any other applications I’m running. I don’t have a duel monitor setup, and a program such as that, will reduce the amount of ‘alt+tab’ing i do.

Last week i created a project on SourceForge. and posted something similar to a Proof of concept on TheNewBoston forums, and uploaded the project on SourceForge,(and i was surprised to find this soon after i uploaded it). Since then i didn’t have much time to work on it.

I’ve started work on the re-writing of the program, some of the new things i’m trying to achieve with it are:

  • Support for multiple images.
  • Reduce memory usage.
  • Support for video.

Here is a screen-shot after some rewriting:

I will re start working on it in about 2-3 weeks, i need to do a few other things first.