Here some snippets of the code.
VLCPlayer Constructor:
Code: Select all
VLCPlayer::VLCPlayer(QWidget *parent,
QRect *_vidRect,
bool _fullscreen,
int _controllerHeight,
int _movieWidth, int
_movieHeight, int
_trackNumber, bool
prevBtn, bool
nextBtn, float
appVol, float
appSavedVol,
bool mute)
: QWidget(parent)
{
...
//preparation of the vlc command
const char * const vlc_args[] = {
"-I", "dummy", /* Don't use any interface */
"--ignore-config", /* Don't use VLC's config */
//"--extraintf=logger", //log anything
//"--verbose=2", //be much more verbose then normal for debugging purpose
"--no-video-title-show",
audioTrack,
"--no-plugins-cache",
#if defined(Q_OS_WIN)
"--plugin-path=.\\plugins"
#elif defined(Q_OS_MAC)
"--plugin-path=./plugins"
#elif // Linux
"--plugin-path=./plugins"
#endif
};
QDesktopWidget *desktop = QApplication::desktop();
QRect screenRect = desktop->screenGeometry(desktop->primaryScreen());
this->screenWidth = screenRect.width();
this->screenHeight = screenRect.height();
this->movieWidth = _movieWidth;
this->movieHeight = _movieHeight;
this->fullScreen = _fullscreen;
this->vidRect = *_vidRect;
this->controllerHeight = _controllerHeight;
this->screenRatio = screenWidth/screenHeight;
_m = NULL; // libvlc_media_player_t *_mp;
_mp = NULL; // libvlc_media_t *_m;
this->_videoWidget=new QFrame(this);
layout = new QVBoxLayout;
layout->addWidget(_videoWidget);
layout->setMargin(0);
layout->setSpacing(0);
setLayout(layout);
...
//Initialize an instance of vlc
//a structure for the exception is neede for this initalization
libvlc_exception_init(&_vlcexcep);
//create a new libvlc instance
_vlcinstance=libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args,&_vlcexcep); //tricky calculation of the char space used
vlcraise (&_vlcexcep);
// Create a media player playing environement
_mp = libvlc_media_player_new(_vlcinstance, &_vlcexcep);
vlcraise(&_vlcexcep);
// Calculate the rectangle for the video
playerRect = this->calcPlayerRect(*_vidRect, (double)16/(double)9 );
this->setGeometry(playerRect.x(), playerRect.y(), playerRect.width(), playerRect.height());
/* Attach event to the media player */
libvlc_event_manager_t* em_mp;
em_mp = libvlc_media_player_event_manager (_mp, &_vlcexcep);
vlcraise (&_vlcexcep);
libvlc_event_attach (em_mp, libvlc_MediaPlayerEndReached, callbacks, this, &_vlcexcep);
vlcraise (&_vlcexcep);
...
}
VLCPlayer playFile:
Code: Select all
VLCPlayer::playFile(QString file)
{
QCursor myCrsr(Qt::WaitCursor);
_videoPath = file;
if (_m) {
libvlc_media_release(_m);
}
/* Create a new LibVLC media descriptor */
_m = libvlc_media_new(_vlcinstance, file.toAscii(), &_vlcexcep);
vlcraise(&_vlcexcep);
libvlc_media_player_set_media (_mp, _m, &_vlcexcep);
vlcraise(&_vlcexcep);
// /!\ Please note /!\
//
// passing the widget to the lib shows vlc at which position it should show up
// vlc automatically resizes the video to the ´given size of the widget
// and it even resizes it, if the size changes at the playing
/* Get our media instance to use our window */
#if defined(Q_OS_WIN)
libvlc_media_player_set_drawable(_mp, reinterpret_cast<unsigned int>(_videoWidget->winId()), &_vlcexcep );
//libvlc_media_player_set_hwnd(_mp, _videoWidget->winId(), &_vlcexcep ); // for vlc 1.0
#elif defined(Q_OS_MAC)
libvlc_media_player_set_drawable(_mp, _videoWidget->winId(), &_vlcexcep );
//libvlc_media_player_set_agl (_mp, _videoWidget->winId(), &_vlcexcep); // for vlc 1.0
#else //Linux
libvlc_media_player_set_drawable(_mp, _videoWidget->winId(), &_vlcexcep );
//libvlc_media_player_set_xwindow(_mp, _videoWidget->winId(), &_vlcexcep ); // for vlc 1.0
#endif
vlcraise(&_vlcexcep);
myCrsr.setShape(Qt::ArrowCursor);
...
this->play();
...
}
playFile() is called from the parentWidget. I tried to call it with a delay, but this did not help.
As I said before it works fine on XP and about 7 of 10 Times on Vista.
Regards
Chris