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
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.
void SetOutputWindow(void* pHwnd);
void SetEventHandler(VLCEventHandler event, void* pUserData);
void OpenMedia(const char* pMediaPathName);
void SetTime(int64_t newTime);
void Mute(bool mute = true);
void SetVolume(int volume);
Using the Code
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:
class CVlcDialogDlg : public CDialog
VLCWrapper vlcPlayer_; .
CStatic vlcControl_; . . .
Now we can initialize the
The handler function for VLC events:
static void HandleVLCEvents(const VLCEvent* pEvent, void* pUserData)
CVlcDialogDlg* pDlg = reinterpret_cast<CVlcDialogDlg*>(pUserData);
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:
- Updated the project to use the VLC API 2.0.0.
- Changed license to CPOL.
- Added project files for Visual Studio 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.
- 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!
VlcDialog (Resizing, Icon-Buttons)
- Striped off dependency to "StdAfx.h" in
class VLCWrapper and
Replaced a deprecated function call to
SetOutputWindow(void*) takes a
void pointer to a window handle
- Some fixes in the example listings