LibVLC SampleCode Qt
This sample code will render a video into a Qt QWidget.
This was tested with vlc-0.9.9 and Qt 4.5.1 on WinXP.
main.cpp:
/* libVLC and Qt sample code
* Copyright © 2009 Alexander Maringer <maringer@maringer-it.de>
*/
#include "vlc_on_qt.h"
#include <QtGui/QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Player p;
p.resize(640,480);
p.playFile("rtp://@:2626");
p.show();
return a.exec();
}
vlc_on_qt.h:
/* libVLC and Qt sample code
* Copyright © 2009 Alexander Maringer <maringer@maringer-it.de>
*/
#ifndef VLC_ON_QT_H
#define VLC_ON_QT_H
#include <vlc/vlc.h>
#include <QWidget>
class QProcess;
class QVBoxLayout;
class QWidget;
class QSizePolicy;
class QPushButton;
class QTextEdit;
class QCloseEvent;
class QTimer;
class QDebug;
class QFrame;
class QSlider;
#define POSITION_RESOLUTION 10000
class Player : public QWidget
{
Q_OBJECT
QSlider *_positionSlider;
QSlider *_volumeSlider;
QFrame *_videoWidget;
QTimer *poller;
bool _isPlaying;
libvlc_exception_t _vlcexcep;
libvlc_instance_t *_vlcinstance;
libvlc_media_player_t *_mp;
libvlc_media_t *_m;
libvlc_media_list_t *_ml;
libvlc_media_list_player_t * _mlp;
public:
Player();
~Player();
void raise(libvlc_exception_t * ex);
public slots:
void playFile(QString file);
void updateInterface();
void changeVolume(int newVolume);
void changePosition(int newPosition);
};
#endif