<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.videolan.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Bedduzzo</id>
	<title>VideoLAN Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.videolan.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Bedduzzo"/>
	<link rel="alternate" type="text/html" href="https://wiki.videolan.org/Special:Contributions/Bedduzzo/"/>
	<updated>2026-11-04T15:56:30Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.11</generator>
	<entry>
		<id>https://wiki.videolan.org/index.php?title=LibVLC_SampleCode_Qt&amp;diff=21167</id>
		<title>LibVLC SampleCode Qt</title>
		<link rel="alternate" type="text/html" href="https://wiki.videolan.org/index.php?title=LibVLC_SampleCode_Qt&amp;diff=21167"/>
		<updated>2012-01-09T13:32:58Z</updated>

		<summary type="html">&lt;p&gt;Bedduzzo: Little code error&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This sample code will render a video into a  Qt QWidget. &lt;br /&gt;
&lt;br /&gt;
This was tested with vlc-0.9.9 and Qt 4.5.1 on WinXP and Linux&lt;br /&gt;
&lt;br /&gt;
== How to use? ==&lt;br /&gt;
&lt;br /&gt;
	 &lt;br /&gt;
You need [[LibVLC|&#039;&#039;libvlc headers&#039;&#039;]] and &#039;&#039;Qt headers&#039;&#039;.Take those 3 files, put them in a folder.&lt;br /&gt;
Run &lt;br /&gt;
 qmake -project&lt;br /&gt;
&lt;br /&gt;
Edit the .pro file and add&lt;br /&gt;
 LIBS += -L*path to vlc lib* #if you are at windows os&lt;br /&gt;
 LIBS += -lvlc&lt;br /&gt;
&lt;br /&gt;
Run&lt;br /&gt;
 qmake&lt;br /&gt;
and then&lt;br /&gt;
 make or mingw32-make under a Windows OS&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
On win os you have to use the zip file. the lib and the header files are located in the sdk-folder.&lt;br /&gt;
&lt;br /&gt;
== VLC 1.1.5 and Ubutnu Lucid ==&lt;br /&gt;
[Ondrej Spilka 20101201] slightly modified for the modest versions...&lt;br /&gt;
- tested ok&lt;br /&gt;
- X11 embed container have to be used, therefore QX11EmbedContainer rather than QFrame have to be used.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Files ==&lt;br /&gt;
&lt;br /&gt;
main.cpp:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* libVLC and Qt sample code&lt;br /&gt;
 * Copyright © 2009 Alexander Maringer &amp;lt;maringer@maringer-it.de&amp;gt;&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;quot;vlc_on_qt.h&amp;quot;&lt;br /&gt;
#include &amp;lt;QtGui/QApplication&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
    QApplication a(argc, argv);&lt;br /&gt;
    Player p;&lt;br /&gt;
    p.resize(640,480);&lt;br /&gt;
    p.playFile(&amp;quot;rtp://@:2626&amp;quot;); // Replace with what you want to play&lt;br /&gt;
    p.show();&lt;br /&gt;
    return a.exec();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
vlc_on_qt.h:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* libVLC and Qt sample code&lt;br /&gt;
 * Copyright © 2009 Alexander Maringer &amp;lt;maringer@maringer-it.de&amp;gt;&lt;br /&gt;
 */&lt;br /&gt;
#ifndef VLC_ON_QT_H&lt;br /&gt;
#define VLC_ON_QT_H&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;vlc/vlc.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QWidget&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class QVBoxLayout;&lt;br /&gt;
class QPushButton;&lt;br /&gt;
class QTimer;&lt;br /&gt;
class QFrame;&lt;br /&gt;
class QSlider;&lt;br /&gt;
&lt;br /&gt;
#define POSITION_RESOLUTION 10000&lt;br /&gt;
&lt;br /&gt;
class Player : public QWidget&lt;br /&gt;
{&lt;br /&gt;
    Q_OBJECT&lt;br /&gt;
    QSlider *_positionSlider;&lt;br /&gt;
    QSlider *_volumeSlider;&lt;br /&gt;
    // [20101201 Ondra Spilka] &lt;br /&gt;
    // on Linux/Ubuntu Lucid and VLC &amp;gt;= 1.0 (at least 1.1.5 was tested) XWindow handle have to be passed&lt;br /&gt;
    // therefore QX11EmbedContainer have to be used instead of QFrame&lt;br /&gt;
#ifdef Q_WS_X11    &lt;br /&gt;
    QX11EmbedContainer *_videoWidget;&lt;br /&gt;
#else&lt;br /&gt;
    QFrame *_videoWidget;&lt;br /&gt;
#endif   &lt;br /&gt;
    QTimer *poller;&lt;br /&gt;
    bool _isPlaying;&lt;br /&gt;
    libvlc_exception_t _vlcexcep;&lt;br /&gt;
    libvlc_instance_t *_vlcinstance;&lt;br /&gt;
    libvlc_media_player_t *_mp;&lt;br /&gt;
    libvlc_media_t *_m;&lt;br /&gt;
&lt;br /&gt;
public:&lt;br /&gt;
    Player();&lt;br /&gt;
    ~Player();&lt;br /&gt;
    void raise(libvlc_exception_t * ex);&lt;br /&gt;
&lt;br /&gt;
public slots:&lt;br /&gt;
    void playFile(QString file);&lt;br /&gt;
    void updateInterface();&lt;br /&gt;
    void changeVolume(int newVolume);&lt;br /&gt;
    void changePosition(int newPosition);&lt;br /&gt;
&lt;br /&gt;
};&lt;br /&gt;
#endif&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
vlc_on_qt.cpp:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* libVLC and Qt sample code&lt;br /&gt;
 * Copyright © 2009 Alexander Maringer &amp;lt;maringer@maringer-it.de&amp;gt;&lt;br /&gt;
 */&lt;br /&gt;
#include &amp;quot;vlc_on_qt.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QVBoxLayout&amp;gt;&lt;br /&gt;
#include &amp;lt;QPushButton&amp;gt;&lt;br /&gt;
#include &amp;lt;QSlider&amp;gt;&lt;br /&gt;
#include &amp;lt;QTimer&amp;gt;&lt;br /&gt;
#include &amp;lt;QFrame&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Player::Player()&lt;br /&gt;
: QWidget()&lt;br /&gt;
{&lt;br /&gt;
    //preparation of the vlc command&lt;br /&gt;
    const char * const vlc_args[] = {&lt;br /&gt;
              &amp;quot;-I&amp;quot;, &amp;quot;dummy&amp;quot;, /* Don&#039;t use any interface */&lt;br /&gt;
              &amp;quot;--ignore-config&amp;quot;, /* Don&#039;t use VLC&#039;s config */&lt;br /&gt;
              &amp;quot;--extraintf=logger&amp;quot;, //log anything&lt;br /&gt;
              &amp;quot;--verbose=2&amp;quot;, //be much more verbose then normal for debugging purpose&lt;br /&gt;
              &amp;quot;--plugin-path=C:\\vlc-0.9.9-win32\\plugins\\&amp;quot; };&lt;br /&gt;
&lt;br /&gt;
#ifdef Q_WS_X11    &lt;br /&gt;
    _videoWidget=new QX11EmbedContainer(this);&lt;br /&gt;
#else&lt;br /&gt;
    _videoWidget=new QFrame(this);&lt;br /&gt;
#endif   &lt;br /&gt;
&lt;br /&gt;
    _volumeSlider=new QSlider(Qt::Horizontal,this);&lt;br /&gt;
    _volumeSlider-&amp;gt;setMaximum(100); //the volume is between 0 and 100&lt;br /&gt;
    _volumeSlider-&amp;gt;setToolTip(&amp;quot;Audio slider&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    // Note: if you use streaming, there is no ability to use the position slider&lt;br /&gt;
    _positionSlider=new QSlider(Qt::Horizontal,this); &lt;br /&gt;
    _positionSlider-&amp;gt;setMaximum(POSITION_RESOLUTION);&lt;br /&gt;
&lt;br /&gt;
    QVBoxLayout *layout = new QVBoxLayout;&lt;br /&gt;
    layout-&amp;gt;addWidget(_videoWidget);&lt;br /&gt;
    layout-&amp;gt;addWidget(_positionSlider);&lt;br /&gt;
    layout-&amp;gt;addWidget(_volumeSlider);&lt;br /&gt;
    setLayout(layout);&lt;br /&gt;
&lt;br /&gt;
    _isPlaying=false;&lt;br /&gt;
    poller=new QTimer(this);&lt;br /&gt;
&lt;br /&gt;
    //Initialize an instance of vlc&lt;br /&gt;
    //a structure for the exception is neede for this initalization&lt;br /&gt;
    libvlc_exception_init(&amp;amp;_vlcexcep);&lt;br /&gt;
&lt;br /&gt;
    //create a new libvlc instance&lt;br /&gt;
    _vlcinstance=libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args,&amp;amp;_vlcexcep);  //tricky calculation of the char space used&lt;br /&gt;
    raise (&amp;amp;_vlcexcep);&lt;br /&gt;
    &lt;br /&gt;
    // Create a media player playing environement &lt;br /&gt;
    _mp = libvlc_media_player_new (_vlcinstance, &amp;amp;_vlcexcep);&lt;br /&gt;
    raise (&amp;amp;_vlcexcep);&lt;br /&gt;
&lt;br /&gt;
    //connect the two sliders to the corresponding slots (uses Qt&#039;s signal / slots technology)&lt;br /&gt;
    connect(poller, SIGNAL(timeout()), this, SLOT(updateInterface()));&lt;br /&gt;
    connect(_positionSlider, SIGNAL(sliderMoved(int)), this, SLOT(changePosition(int)));&lt;br /&gt;
    connect(_volumeSlider, SIGNAL(sliderMoved(int)), this, SLOT(changeVolume(int)));&lt;br /&gt;
&lt;br /&gt;
    poller-&amp;gt;start(100); //start timer to trigger every 100 ms the updateInterface slot&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//desctructor&lt;br /&gt;
Player::~Player()&lt;br /&gt;
{&lt;br /&gt;
    /* Stop playing */&lt;br /&gt;
    libvlc_media_player_stop (_mp, &amp;amp;_vlcexcep);&lt;br /&gt;
&lt;br /&gt;
    /* Free the media_player */&lt;br /&gt;
    libvlc_media_player_release (_mp);&lt;br /&gt;
&lt;br /&gt;
    libvlc_release (_vlcinstance);&lt;br /&gt;
    raise (&amp;amp;_vlcexcep);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void Player::playFile(QString file)&lt;br /&gt;
{&lt;br /&gt;
    //the file has to be in one of the following formats /perhaps a little bit outdated)&lt;br /&gt;
    /*&lt;br /&gt;
    [file://]filename              Plain media file&lt;br /&gt;
    http://ip:port/file            HTTP URL&lt;br /&gt;
    ftp://ip:port/file             FTP URL&lt;br /&gt;
    mms://ip:port/file             MMS URL&lt;br /&gt;
    screen://                      Screen capture&lt;br /&gt;
    [dvd://][device][@raw_device]  DVD device&lt;br /&gt;
    [vcd://][device]               VCD device&lt;br /&gt;
    [cdda://][device]              Audio CD device&lt;br /&gt;
    udp:[[&amp;lt;source address&amp;gt;]@[&amp;lt;bind address&amp;gt;][:&amp;lt;bind port&amp;gt;]]&lt;br /&gt;
    */&lt;br /&gt;
&lt;br /&gt;
    /* Create a new LibVLC media descriptor */&lt;br /&gt;
    _m = libvlc_media_new (_vlcinstance, file.toAscii(), &amp;amp;_vlcexcep);&lt;br /&gt;
    raise(&amp;amp;_vlcexcep);&lt;br /&gt;
    &lt;br /&gt;
    libvlc_media_player_set_media (_mp, _m, &amp;amp;_vlcexcep);&lt;br /&gt;
    raise(&amp;amp;_vlcexcep);&lt;br /&gt;
&lt;br /&gt;
    // /!\ Please note /!\&lt;br /&gt;
    //&lt;br /&gt;
    // passing the widget to the lib shows vlc at which position it should show up&lt;br /&gt;
    // vlc automatically resizes the video to the ´given size of the widget&lt;br /&gt;
    // and it even resizes it, if the size changes at the playing&lt;br /&gt;
    &lt;br /&gt;
    /* Get our media instance to use our window */&lt;br /&gt;
    #if defined(Q_OS_WIN)&lt;br /&gt;
        libvlc_media_player_set_drawable(_mp, reinterpret_cast&amp;lt;unsigned int&amp;gt;(_videoWidget-&amp;gt;winId()), &amp;amp;_vlcexcep );&lt;br /&gt;
        //libvlc_media_player_set_hwnd(_mp, _videoWidget-&amp;gt;winId(), &amp;amp;_vlcexcep ); // for vlc 1.0&lt;br /&gt;
    #elif defined(Q_OS_MAC)&lt;br /&gt;
        libvlc_media_player_set_drawable(_mp, _videoWidget-&amp;gt;winId(), &amp;amp;_vlcexcep );&lt;br /&gt;
        //libvlc_media_player_set_agl (_mp, _videoWidget-&amp;gt;winId(), &amp;amp;_vlcexcep); // for vlc 1.0&lt;br /&gt;
    #else //Linux&lt;br /&gt;
        //[20101201 Ondrej Spilka] obsolete call on libVLC &amp;gt;=1.1.5 &lt;br /&gt;
        //libvlc_media_player_set_drawable(_mp, _videoWidget-&amp;gt;winId(), &amp;amp;_vlcexcep );&lt;br /&gt;
        //libvlc_media_player_set_xwindow(_mp, _videoWidget-&amp;gt;winId(), &amp;amp;_vlcexcep ); // for vlc 1.0&lt;br /&gt;
&lt;br /&gt;
     /* again note X11 handle on Linux is needed&lt;br /&gt;
        winID() returns X11 handle when QX11EmbedContainer us used */&lt;br /&gt;
     &lt;br /&gt;
        int windid = _videoWidget-&amp;gt;winId();&lt;br /&gt;
        libvlc_media_player_set_xwindow (mp, windid );&lt;br /&gt;
&lt;br /&gt;
    #endif&lt;br /&gt;
    raise(&amp;amp;_vlcexcep);&lt;br /&gt;
&lt;br /&gt;
    /* Play */&lt;br /&gt;
    libvlc_media_player_play (_mp, &amp;amp;_vlcexcep );&lt;br /&gt;
    raise(&amp;amp;_vlcexcep);&lt;br /&gt;
&lt;br /&gt;
    _isPlaying=true;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void Player::changeVolume(int newVolume)&lt;br /&gt;
{&lt;br /&gt;
    libvlc_exception_clear(&amp;amp;_vlcexcep);&lt;br /&gt;
    libvlc_audio_set_volume (_vlcinstance,newVolume , &amp;amp;_vlcexcep);&lt;br /&gt;
    raise(&amp;amp;_vlcexcep);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void Player::changePosition(int newPosition)&lt;br /&gt;
{&lt;br /&gt;
    libvlc_exception_clear(&amp;amp;_vlcexcep);&lt;br /&gt;
    // It&#039;s possible that the vlc doesn&#039;t play anything&lt;br /&gt;
    // so check before&lt;br /&gt;
    libvlc_media_t *curMedia = libvlc_media_player_get_media (_mp, &amp;amp;_vlcexcep);&lt;br /&gt;
    libvlc_exception_clear(&amp;amp;_vlcexcep);&lt;br /&gt;
    if (curMedia == NULL)&lt;br /&gt;
        return;&lt;br /&gt;
&lt;br /&gt;
    float pos=(float)(newPosition)/(float)POSITION_RESOLUTION;&lt;br /&gt;
    libvlc_media_player_set_position (_mp, pos, &amp;amp;_vlcexcep);&lt;br /&gt;
    raise(&amp;amp;_vlcexcep);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void Player::updateInterface()&lt;br /&gt;
{&lt;br /&gt;
    if(!_isPlaying)&lt;br /&gt;
        return;&lt;br /&gt;
&lt;br /&gt;
    // It&#039;s possible that the vlc doesn&#039;t play anything&lt;br /&gt;
    // so check before&lt;br /&gt;
    libvlc_media_t *curMedia = libvlc_media_player_get_media (_mp, &amp;amp;_vlcexcep);&lt;br /&gt;
    libvlc_exception_clear(&amp;amp;_vlcexcep);&lt;br /&gt;
    if (curMedia == NULL)&lt;br /&gt;
        return;&lt;br /&gt;
&lt;br /&gt;
    float pos=libvlc_media_player_get_position (_mp, &amp;amp;_vlcexcep);&lt;br /&gt;
    int siderPos=(int)(pos*(float)(POSITION_RESOLUTION));&lt;br /&gt;
    _positionSlider-&amp;gt;setValue(siderPos);&lt;br /&gt;
    int volume=libvlc_audio_get_volume (_vlcinstance,&amp;amp;_vlcexcep);&lt;br /&gt;
    _volumeSlider-&amp;gt;setValue(volume);&lt;br /&gt;
}&lt;br /&gt;
void Player::raise(libvlc_exception_t * ex)&lt;br /&gt;
{&lt;br /&gt;
    if (libvlc_exception_raised (ex))&lt;br /&gt;
    {&lt;br /&gt;
         fprintf (stderr, &amp;quot;error: %s\n&amp;quot;, libvlc_exception_get_message(ex));&lt;br /&gt;
         exit (-1);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== VLC 1.2 and OpenSuse 11.3 ==&lt;br /&gt;
[Jofre Guevara 20101215] Modifications of original template based on new VLC version.&lt;br /&gt;
[Ondrej Spilka 20101201] slightly modified for the modest versions...&lt;br /&gt;
- tested ok&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Files ==&lt;br /&gt;
&lt;br /&gt;
main.cpp:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* libVLC and Qt sample code&lt;br /&gt;
 * Copyright © 2009 Alexander Maringer &amp;lt;maringer@maringer-it.de&amp;gt;&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
#include &amp;quot;vlc_on_qt.h&amp;quot;&lt;br /&gt;
#include &amp;lt;QtGui/QApplication&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
    QApplication a(argc, argv);&lt;br /&gt;
    Player p;&lt;br /&gt;
    p.resize(640,480);&lt;br /&gt;
    p.playFile(&amp;quot;rtp://@:2626&amp;quot;); // Replace with what you want to play&lt;br /&gt;
    p.show();&lt;br /&gt;
    return a.exec();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
vlc_on_qt.h:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* libVLC and Qt sample code&lt;br /&gt;
 * Copyright © 2009 Alexander Maringer &amp;lt;maringer@maringer-it.de&amp;gt;&lt;br /&gt;
 */&lt;br /&gt;
#ifndef VLC_ON_QT_H&lt;br /&gt;
#define VLC_ON_QT_H&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;vlc/vlc.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QWidget&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class QVBoxLayout;&lt;br /&gt;
class QPushButton;&lt;br /&gt;
class QTimer;&lt;br /&gt;
class QFrame;&lt;br /&gt;
class QSlider;&lt;br /&gt;
&lt;br /&gt;
#define POSITION_RESOLUTION 10000&lt;br /&gt;
&lt;br /&gt;
class Player : public QWidget&lt;br /&gt;
{&lt;br /&gt;
    Q_OBJECT&lt;br /&gt;
    QSlider *_positionSlider;&lt;br /&gt;
    QSlider *_volumeSlider;&lt;br /&gt;
    // [20101215 JG]&lt;br /&gt;
    // Tested on Linux OpenSuse and VLC 1.2.0. This version of VLC is not completely compatible with previous versions of VLC.&lt;br /&gt;
    // [20101201 Ondra Spilka]&lt;br /&gt;
    // on Linux/Ubuntu Lucid and VLC &amp;gt;= 1.0 (at least 1.1.5 was tested) XWindow handle have to be passed&lt;br /&gt;
    // therefore QX11EmbedContainer have to be used instead of QFrame&lt;br /&gt;
#ifdef Q_WS_X11&lt;br /&gt;
    QX11EmbedContainer *_videoWidget;&lt;br /&gt;
#else&lt;br /&gt;
    QFrame *_videoWidget;&lt;br /&gt;
#endif&lt;br /&gt;
    // [20101215 JG] If KDE is used like unique desktop environment, only use QFrame *_videoWidget;&lt;br /&gt;
    QTimer *poller;&lt;br /&gt;
    bool _isPlaying;&lt;br /&gt;
    //libvlc_exception_t _vlcexcep; // [20101215 JG] Used for versions prior to VLC 1.2.0.&lt;br /&gt;
    libvlc_instance_t *_vlcinstance;&lt;br /&gt;
    libvlc_media_player_t *_mp;&lt;br /&gt;
    libvlc_media_t *_m;&lt;br /&gt;
&lt;br /&gt;
public:&lt;br /&gt;
    Player();&lt;br /&gt;
    ~Player();&lt;br /&gt;
    //void raise(libvlc_exception_t * ex); // [20101215 JG] Used for versions prior to VLC 1.2.0.&lt;br /&gt;
&lt;br /&gt;
public slots:&lt;br /&gt;
    void playFile(QString file);&lt;br /&gt;
    void updateInterface();&lt;br /&gt;
    void changeVolume(int newVolume);&lt;br /&gt;
    void changePosition(int newPosition);&lt;br /&gt;
&lt;br /&gt;
};&lt;br /&gt;
#endif&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
vlc_on_qt.cpp:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* libVLC and Qt sample code&lt;br /&gt;
 * Copyright © 2009 Alexander Maringer &amp;lt;maringer@maringer-it.de&amp;gt;&lt;br /&gt;
 */&lt;br /&gt;
#include &amp;quot;vlc_on_qt.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QVBoxLayout&amp;gt;&lt;br /&gt;
#include &amp;lt;QPushButton&amp;gt;&lt;br /&gt;
#include &amp;lt;QSlider&amp;gt;&lt;br /&gt;
#include &amp;lt;QTimer&amp;gt;&lt;br /&gt;
#include &amp;lt;QFrame&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Player::Player()&lt;br /&gt;
: QWidget()&lt;br /&gt;
{&lt;br /&gt;
    //preparation of the vlc command&lt;br /&gt;
    const char * const vlc_args[] = {&lt;br /&gt;
              &amp;quot;-I&amp;quot;, &amp;quot;dummy&amp;quot;, /* Don&#039;t use any interface */&lt;br /&gt;
              &amp;quot;--ignore-config&amp;quot;, /* Don&#039;t use VLC&#039;s config */&lt;br /&gt;
              &amp;quot;--extraintf=logger&amp;quot;, //log anything&lt;br /&gt;
              &amp;quot;--verbose=2&amp;quot;, //be much more verbose then normal for debugging purpose&lt;br /&gt;
              &amp;quot;--plugin-path=C:\\vlc-0.9.9-win32\\plugins\\&amp;quot; };&lt;br /&gt;
&lt;br /&gt;
#ifdef Q_WS_X11&lt;br /&gt;
    _videoWidget=new QX11EmbedContainer(this);&lt;br /&gt;
#else&lt;br /&gt;
    _videoWidget=new QFrame(this);&lt;br /&gt;
#endif&lt;br /&gt;
    // [20101215 JG] If KDE is used like unique desktop environment, only use _videoWidget=new QFrame(this);&lt;br /&gt;
&lt;br /&gt;
    _volumeSlider=new QSlider(Qt::Horizontal,this);&lt;br /&gt;
    _volumeSlider-&amp;gt;setMaximum(100); //the volume is between 0 and 100&lt;br /&gt;
    _volumeSlider-&amp;gt;setToolTip(&amp;quot;Audio slider&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    // Note: if you use streaming, there is no ability to use the position slider&lt;br /&gt;
    _positionSlider=new QSlider(Qt::Horizontal,this);&lt;br /&gt;
    _positionSlider-&amp;gt;setMaximum(POSITION_RESOLUTION);&lt;br /&gt;
&lt;br /&gt;
    QVBoxLayout *layout = new QVBoxLayout;&lt;br /&gt;
    layout-&amp;gt;addWidget(_videoWidget);&lt;br /&gt;
    layout-&amp;gt;addWidget(_positionSlider);&lt;br /&gt;
    layout-&amp;gt;addWidget(_volumeSlider);&lt;br /&gt;
    setLayout(layout);&lt;br /&gt;
&lt;br /&gt;
    _isPlaying=false;&lt;br /&gt;
    poller=new QTimer(this);&lt;br /&gt;
&lt;br /&gt;
    //Initialize an instance of vlc&lt;br /&gt;
    //a structure for the exception is neede for this initalization&lt;br /&gt;
    //libvlc_exception_init(&amp;amp;_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0.&lt;br /&gt;
&lt;br /&gt;
    //create a new libvlc instance&lt;br /&gt;
    _vlcinstance=libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args);  //tricky calculation of the char space used&lt;br /&gt;
    //_vlcinstance=libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args,&amp;amp;_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0.&lt;br /&gt;
    //raise (&amp;amp;_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0.&lt;br /&gt;
&lt;br /&gt;
    // Create a media player playing environement&lt;br /&gt;
    _mp = libvlc_media_player_new (_vlcinstance);&lt;br /&gt;
    //_mp = libvlc_media_player_new (_vlcinstance, &amp;amp;_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0.&lt;br /&gt;
    //raise (&amp;amp;_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0.&lt;br /&gt;
&lt;br /&gt;
    //connect the two sliders to the corresponding slots (uses Qt&#039;s signal / slots technology)&lt;br /&gt;
    connect(poller, SIGNAL(timeout()), this, SLOT(updateInterface()));&lt;br /&gt;
    connect(_positionSlider, SIGNAL(sliderMoved(int)), this, SLOT(changePosition(int)));&lt;br /&gt;
    connect(_volumeSlider, SIGNAL(sliderMoved(int)), this, SLOT(changeVolume(int)));&lt;br /&gt;
&lt;br /&gt;
    poller-&amp;gt;start(100); //start timer to trigger every 100 ms the updateInterface slot&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//desctructor&lt;br /&gt;
Player::~Player()&lt;br /&gt;
{&lt;br /&gt;
    /* Stop playing */&lt;br /&gt;
    libvlc_media_player_stop (_mp);&lt;br /&gt;
    //libvlc_media_player_stop (_mp, &amp;amp;_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0.&lt;br /&gt;
&lt;br /&gt;
    /* Free the media_player */&lt;br /&gt;
    libvlc_media_player_release (_mp);&lt;br /&gt;
&lt;br /&gt;
    libvlc_release (_vlcinstance);&lt;br /&gt;
    //raise (&amp;amp;_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void Player::playFile(QString file)&lt;br /&gt;
{&lt;br /&gt;
    //the file has to be in one of the following formats /perhaps a little bit outdated)&lt;br /&gt;
    /*&lt;br /&gt;
    [file://]filename              Plain media file&lt;br /&gt;
    http://ip:port/file            HTTP URL&lt;br /&gt;
    ftp://ip:port/file             FTP URL&lt;br /&gt;
    mms://ip:port/file             MMS URL&lt;br /&gt;
    screen://                      Screen capture&lt;br /&gt;
    [dvd://][device][@raw_device]  DVD device&lt;br /&gt;
    [vcd://][device]               VCD device&lt;br /&gt;
    [cdda://][device]              Audio CD device&lt;br /&gt;
    udp:[[&amp;lt;source address&amp;gt;]@[&amp;lt;bind address&amp;gt;][:&amp;lt;bind port&amp;gt;]]&lt;br /&gt;
    */&lt;br /&gt;
&lt;br /&gt;
    /* Create a new LibVLC media descriptor */&lt;br /&gt;
    _m = libvlc_media_new_path(_vlcinstance, file.toAscii());&lt;br /&gt;
    //_m = libvlc_media_new (_vlcinstance, file.toAscii(), &amp;amp;_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0.&lt;br /&gt;
    //raise(&amp;amp;_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0.&lt;br /&gt;
&lt;br /&gt;
    libvlc_media_player_set_media (_mp, _m);&lt;br /&gt;
    //libvlc_media_player_set_media (_mp, _m, &amp;amp;_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0.&lt;br /&gt;
    //raise(&amp;amp;_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0.&lt;br /&gt;
&lt;br /&gt;
    // /!\ Please note /!\&lt;br /&gt;
    //&lt;br /&gt;
    // passing the widget to the lib shows vlc at which position it should show up&lt;br /&gt;
    // vlc automatically resizes the video to the ´given size of the widget&lt;br /&gt;
    // and it even resizes it, if the size changes at the playing&lt;br /&gt;
&lt;br /&gt;
    /* Get our media instance to use our window */&lt;br /&gt;
    #if defined(Q_OS_WIN)&lt;br /&gt;
        libvlc_media_player_set_drawable(_mp, reinterpret_cast&amp;lt;unsigned int&amp;gt;(_videoWidget-&amp;gt;winId()));&lt;br /&gt;
        //libvlc_media_player_set_drawable(_mp, reinterpret_cast&amp;lt;unsigned int&amp;gt;(_videoWidget-&amp;gt;winId()), &amp;amp;_vlcexcep ); // [20101215 JG] Used for versions prior to VLC 1.2.0.&lt;br /&gt;
        //libvlc_media_player_set_hwnd(_mp, _videoWidget-&amp;gt;winId(), &amp;amp;_vlcexcep ); // for vlc 1.0&lt;br /&gt;
    #elif defined(Q_OS_MAC)&lt;br /&gt;
        libvlc_media_player_set_drawable(_mp, _videoWidget-&amp;gt;winId());&lt;br /&gt;
        //libvlc_media_player_set_drawable(_mp, _videoWidget-&amp;gt;winId(), &amp;amp;_vlcexcep ); // [20101215 JG] Used for versions prior to VLC 1.2.0.&lt;br /&gt;
        //libvlc_media_player_set_agl (_mp, _videoWidget-&amp;gt;winId(), &amp;amp;_vlcexcep); // for vlc 1.0&lt;br /&gt;
    #else //Linux&lt;br /&gt;
        //[20101201 Ondrej Spilka] obsolete call on libVLC &amp;gt;=1.1.5&lt;br /&gt;
        //libvlc_media_player_set_drawable(_mp, _videoWidget-&amp;gt;winId(), &amp;amp;_vlcexcep );&lt;br /&gt;
        //libvlc_media_player_set_xwindow(_mp, _videoWidget-&amp;gt;winId(), &amp;amp;_vlcexcep ); // for vlc 1.0&lt;br /&gt;
&lt;br /&gt;
     /* again note X11 handle on Linux is needed&lt;br /&gt;
        winID() returns X11 handle when QX11EmbedContainer us used */&lt;br /&gt;
&lt;br /&gt;
        int windid = _videoWidget-&amp;gt;winId();&lt;br /&gt;
        libvlc_media_player_set_xwindow (_mp, windid );&lt;br /&gt;
&lt;br /&gt;
    #endif&lt;br /&gt;
    //raise(&amp;amp;_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0.&lt;br /&gt;
&lt;br /&gt;
    /* Play */&lt;br /&gt;
    libvlc_media_player_play (_mp);&lt;br /&gt;
    //libvlc_media_player_play (_mp, &amp;amp;_vlcexcep ); // [20101215 JG] Used for versions prior to VLC 1.2.0.&lt;br /&gt;
    //raise(&amp;amp;_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0.&lt;br /&gt;
&lt;br /&gt;
    _isPlaying=true;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void Player::changeVolume(int newVolume)&lt;br /&gt;
{&lt;br /&gt;
    //libvlc_exception_clear(&amp;amp;_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0.&lt;br /&gt;
    libvlc_audio_set_volume (_mp,newVolume);&lt;br /&gt;
    //libvlc_audio_set_volume (_vlcinstance,newVolume , &amp;amp;_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0.&lt;br /&gt;
    //raise(&amp;amp;_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void Player::changePosition(int newPosition)&lt;br /&gt;
{&lt;br /&gt;
    //libvlc_exception_clear(&amp;amp;_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0.&lt;br /&gt;
    // It&#039;s possible that the vlc doesn&#039;t play anything&lt;br /&gt;
    // so check before&lt;br /&gt;
    libvlc_media_t *curMedia = libvlc_media_player_get_media (_mp);&lt;br /&gt;
    //libvlc_media_t *curMedia = libvlc_media_player_get_media (_mp, &amp;amp;_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0.&lt;br /&gt;
    //libvlc_exception_clear(&amp;amp;_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0.&lt;br /&gt;
    if (curMedia == NULL)&lt;br /&gt;
        return;&lt;br /&gt;
&lt;br /&gt;
    float pos=(float)(newPosition)/(float)POSITION_RESOLUTION;&lt;br /&gt;
    libvlc_media_player_set_position (_mp, pos);&lt;br /&gt;
    //libvlc_media_player_set_position (_mp, pos, &amp;amp;_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0.&lt;br /&gt;
    //raise(&amp;amp;_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void Player::updateInterface()&lt;br /&gt;
{&lt;br /&gt;
    if(!_isPlaying)&lt;br /&gt;
        return;&lt;br /&gt;
&lt;br /&gt;
    // It&#039;s possible that the vlc doesn&#039;t play anything&lt;br /&gt;
    // so check before&lt;br /&gt;
    libvlc_media_t *curMedia = libvlc_media_player_get_media (_mp);&lt;br /&gt;
    //libvlc_media_t *curMedia = libvlc_media_player_get_media (_mp, &amp;amp;_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0.&lt;br /&gt;
    //libvlc_exception_clear(&amp;amp;_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0.&lt;br /&gt;
    if (curMedia == NULL)&lt;br /&gt;
        return;&lt;br /&gt;
&lt;br /&gt;
    float pos=libvlc_media_player_get_position (_mp);&lt;br /&gt;
    //float pos=libvlc_media_player_get_position (_mp, &amp;amp;_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0.&lt;br /&gt;
    int siderPos=(int)(pos*(float)(POSITION_RESOLUTION));&lt;br /&gt;
    _positionSlider-&amp;gt;setValue(siderPos);&lt;br /&gt;
    int volume=libvlc_audio_get_volume (_mp);&lt;br /&gt;
    //int volume=libvlc_audio_get_volume (_vlcinstance,&amp;amp;_vlcexcep); // [20101215 JG] Used for versions prior to VLC 1.2.0.&lt;br /&gt;
    _volumeSlider-&amp;gt;setValue(volume);&lt;br /&gt;
}&lt;br /&gt;
/*void Player::raise(libvlc_exception_t * ex)&lt;br /&gt;
{&lt;br /&gt;
    if (libvlc_exception_raised (ex))&lt;br /&gt;
    {&lt;br /&gt;
         fprintf (stderr, &amp;quot;error: %s\n&amp;quot;, libvlc_exception_get_message(ex));&lt;br /&gt;
         exit (-1);&lt;br /&gt;
    }&lt;br /&gt;
}*/  // [20101215 JG] Used for versions prior to VLC 1.2.0.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Bedduzzo</name></author>
	</entry>
</feed>