Click here to Skip to main content
13,795,627 members
Click here to Skip to main content
Add your own
alternative version


165 bookmarked
Posted 13 Aug 2009
Licenced CPOL

VLCWrapper - A Little C++-wrapper Around libvlc

, 12 Mar 2012
Rate this:
Please Sign up or sign in to vote.
An article on wrapping libvlc (VLC media player) in a C++-class


This article presents a little C++-wrapper for the libvlc-library, which is the core component of the VLC media player. I was looking for an easy way to integrate video playback in my C++ applications. Because I've been using VLC for media playback for many years now, I started playing around with the VLC API. The result is a little wrapper around the libvlc-library. It provides basic media playback functionality. Since v.2.0 the  libvlc-library is released under the LGPL, so you can use it in commercial applications. All sourcecode in this arcticle is licensed under the CPOL. Please excuse any bugs because this wrapper is more a quick hack than a feature complete wrapper. ;)

For testing purposes, I wrote a simple media player which uses the VLCWrapper. It's included in the example above.


The most valuable source of information about the VLC API for me was the developer section on the VLC website and the documented C-headers of the VLC source. The project website is a good starting point if you plan to code something with VLC or extend the VLCWrapper.

The C++-Interface of VLCWrapper to LIBVLC

The interface declared in "VLCWrapper.h" is small and the member functions are quite self-explanatory. To get a good overlook, I stripped of the comments. Check out the sources for more information.  

class VLCWrapper
    std::auto_ptr<VLCWrapperImpl> pImpl_;
    void SetOutputWindow(void* pHwnd);
    void SetEventHandler(VLCEventHandler event, void* pUserData);
    void OpenMedia(const char* pMediaPathName);
    void Play();
    void Pause();
    void Stop();
    int64_t GetLength();
    int64_t GetTime();
    void SetTime(int64_t newTime);
    void Mute(bool mute = true);
    bool GetMute();
    int  GetVolume();
    void SetVolume(int volume);

Using the Code

Using the VLCWrapper is easy. The first step would be to add a new VLCWraper as a member of your window class and a CStatic for video output:

#include "VLCWrapper.h"

class CVlcDialogDlg : public CDialog
    VLCWrapper vlcPlayer_; /// Our VLCWrapper.
    CStatic vlcControl_;  /// This CStatic will be used as device context by libvlc.
    . . . 

Now we can initialize the VLCWrapper in OnInitDialog():

BOOL CVlcDialogDlg::OnInitDialog()

    vlcPlayer_.SetOutputWindow((void*)vlcControl_.GetSafeHwnd()); // the CStatic will be 
							          // used for video output

    vlcPlayer_.SetEventHandler(&HandleVLCEvents, this);           // Set handler for vlc events

The handler function for VLC events:

static void HandleVLCEvents(const VLCEvent* pEvent, void* pUserData)
    CVlcDialogDlg* pDlg = reinterpret_cast<CVlcDialogDlg*>(pUserData); 
    case libvlc_MediaPlayerTimeChanged:
       TRACE("VLC_EVT_TIME_CHANGED: new_time %d[ms]\n",

Now everything is in place, and you can start playing media files. E.g., the "Load" and "Play" members look like this:

void CVlcDialogDlg::OnBnClickedButtonLoad()
    CFileDialog dlgFile(TRUE);
        CString file=dlgFile.GetPathName();
        vlcPlayer_.Play();  // start media after loading....

void CVlcDialogDlg::OnBnClickedButtonPlay()


  • 03/12/2012 
    • Updated the project to use the VLC API 2.0.0.
    • Changed license to CPOL.  
  • 09/20/2011 
    • Added project files for Visual Studio 2010. 
  • 09/11/2010
    • Some bugfixes and optimizations, thanks to heretic13!
    • Build the demo with VLC 1.1.4.
    • Removed demo & source links to old VLCDialog versions which required VLC < 1.1.
  • 05/29/2010
    • Updated the project to use the VLC API 1.1
    • The wrapper now uses an auto_ptr for its Pimpl. I missed deleting the Pimpl in the first versions
    • Fixed a redraw error
    • Thanks to Haim Engler for the hint on the memory leak and the redraw problem!
  • 08/20/2009
    • Pimped VlcDialog (Resizing, Icon-Buttons)
    • Striped off dependency to "StdAfx.h" in class VLCWrapper and class VLCWrapperImpl
    • Replaced a deprecated function call to libvlc; now SetOutputWindow(void*) takes a void pointer to a window handle
  • 08/14/2009
    • Some fixes in the example listings
  • 08/11/2009
    • Initial release


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Alex Skoruppa
Technical Lead HERE, a Nokia Business
Germany Germany
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionHow to create a playlist Pin
Ionut Codrut26-Sep-17 2:57
memberIonut Codrut26-Sep-17 2:57 
QuestionStreaming HTTP/RTSP Pin
Member 128338735-Nov-16 2:01
memberMember 128338735-Nov-16 2:01 
AnswerRe: Streaming HTTP/RTSP Pin
hhohho6-Nov-18 19:24
memberhhohho6-Nov-18 19:24 
QuestionFullScreen Pin
Paulraj853-Feb-16 1:39
memberPaulraj853-Feb-16 1:39 
QuestionIs it possible to integrate libvlc with drm sdk Pin
Member 1176913611-Jan-16 5:44
memberMember 1176913611-Jan-16 5:44 
QuestionInput for analyze VLCwrapper Pin
Member 122446477-Jan-16 1:29
memberMember 122446477-Jan-16 1:29 
QuestionVersion of vlc Pin
Member 113573716-Jan-15 19:57
memberMember 113573716-Jan-15 19:57 
Questionan excellent program^^ Pin
kwon, sung-il1-Jan-15 0:11
memberkwon, sung-il1-Jan-15 0:11 
QuestionMessage Removed Pin
12-Aug-14 2:11
memberszulak12-Aug-14 2:11 
Questionlibvlc.dll and libvlccore.dll Pin
Member 1090496226-Jun-14 22:28
memberMember 1090496226-Jun-14 22:28 
SuggestionIf it crashes Pin
KarstenK21-May-14 3:49
mvpKarstenK21-May-14 3:49 
GeneralRe: If it crashes Pin
alaa hassan20-Aug-16 11:44
memberalaa hassan20-Aug-16 11:44 
QuestionReduce the delay(VLC Network streaming) Pin
Member 1052751210-Feb-14 20:04
memberMember 1052751210-Feb-14 20:04 
GeneralWin7 & vx2010 Pin
Alice4720-Jan-14 4:46
professionalAlice4720-Jan-14 4:46 
QuestionIt doesn't support playing video which's name is chinese Pin
ftai22-Dec-13 15:48
memberftai22-Dec-13 15:48 
Questionvs2010+vlc2.1.2 crashing Pin
ftai19-Dec-13 17:14
memberftai19-Dec-13 17:14 
AnswerRe: vs2010+vlc2.1.2 crashing Pin
ftai19-Dec-13 19:10
memberftai19-Dec-13 19:10 
Bugget Error 1 error LNK1123: failure during conversion to COFF: Pin
Member 934496014-Nov-13 5:39
memberMember 934496014-Nov-13 5:39 
QuestionView the start frame only Pin
Member 1029442825-Sep-13 3:44
professionalMember 1029442825-Sep-13 3:44 
QuestionVolume and Mute Pin
deBoozaAgain14-Aug-13 23:38
memberdeBoozaAgain14-Aug-13 23:38 
Questionsuccessful! Pin
Phong Le Thanh2-Aug-13 0:20
memberPhong Le Thanh2-Aug-13 0:20 
GeneralThanks Pin
MaxwellG9-May-13 2:38
memberMaxwellG9-May-13 2:38 
Questionhelp Pin
angel_boom28-Mar-13 1:18
memberangel_boom28-Mar-13 1:18 
GeneralMy vote of 5 Pin
Bartlomiej Filipek23-Mar-13 6:20
memberBartlomiej Filipek23-Mar-13 6:20 
QuestionProblems with http access Pin
Member 959508022-Nov-12 5:44
memberMember 959508022-Nov-12 5:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web06 | 2.8.181207.3 | Last Updated 12 Mar 2012
Article Copyright 2009 by Alex Skoruppa
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid