Qt4.8.3 + MacOSX 10.8 + libVLC > 2.0.1 = crash
Posted: 20 Oct 2012 14:29
I have a problem with libVLC > 2.0.1 on Mac Mountain Lion (64bit) when using libVLC in a Qt application. Every time I try to display the video the app crashes.
I'm using libVLC from VLC (64bit only), Qt 4.8.3, OSX 10.8.2 64bit
This worked fine with libVLC2.0.1 but since 2.0.3 it always crashes. Almost the same code on Windows / Linux works without a problem also with libVLC 2.0.4.
I wrote a simple test application which shows this behavior.
This is mainwindow.h
This is mainwindow.cpp
Is this a known limitation? As I told it works until 2.0.1 but any newer version crashes. Do I have a problem in my code or is there a workaround?
Here you can download the whole source code as tgz package. http://rt.coujo.de/qtplay.tgz
Thank you for your help!
Best regards,
Jörg
I'm using libVLC from VLC (64bit only), Qt 4.8.3, OSX 10.8.2 64bit
This worked fine with libVLC2.0.1 but since 2.0.3 it always crashes. Almost the same code on Windows / Linux works without a problem also with libVLC 2.0.4.
I wrote a simple test application which shows this behavior.
This is mainwindow.h
Code: Select all
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <vlc/vlc.h>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_pushPlay_clicked();
void on_pushStop_clicked();
void on_pushGetFile_clicked();
private:
Ui::MainWindow *ui;
libvlc_media_player_t *_player;
libvlc_instance_t *_lib;
};
#endif // MAINWINDOW_H
Code: Select all
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
_lib = NULL;
_player = NULL;
// create a new libvlc instance ...
const char *vlc_args[] = {
"--ignore-config",
"--intf=dummy",
"--no-media-library",
"--no-osd",
"--no-stats",
"--no-video-title-show",
#ifdef Q_WS_MAC
// vout as well as opengl-provider MIGHT be "minimal_macosx" ...
"--vout=macosx",
#endif
"--verbose=1"
};
int argc = sizeof(vlc_args) / sizeof(vlc_args[0]);
const char ** argv = vlc_args;
_lib = libvlc_new(argc, argv);
_player = libvlc_media_player_new(_lib);
#ifdef Q_OS_WIN
libvlc_media_player_set_hwnd (_player, (void *)ui->frame->winId());
#elif defined Q_OS_MAC
libvlc_media_player_set_nsobject(_player, (void *)ui->frame->winId());
#else
libvlc_media_player_set_xwindow(_player, ui->frame->winId());
#endif
}
MainWindow::~MainWindow()
{
libvlc_media_player_stop(_player);
libvlc_media_player_release (_player);
libvlc_release(_lib);
delete ui;
}
void MainWindow::on_pushPlay_clicked()
{
if (ui->lineFile->text() != "")
{
libvlc_media_t* video = libvlc_media_new_path(_lib, ui->lineFile->text().toUtf8().constData());
if (video)
{
libvlc_media_player_set_media (_player, video);
libvlc_media_release (video);
libvlc_media_player_play (_player);
}
}
}
void MainWindow::on_pushStop_clicked()
{
if (libvlc_media_player_is_playing (_player))
{
libvlc_media_player_stop (_player);
}
}
void MainWindow::on_pushGetFile_clicked()
{
QString file = QFileDialog::getOpenFileName(this, tr("Open Media File"), QString(), tr("Matroshka (*.mkv);;Mpeg4 (*.m4?);;All Files (*.*)"));
if (file != "")
{
ui->lineFile->setText(file);
}
}
Here you can download the whole source code as tgz package. http://rt.coujo.de/qtplay.tgz
Thank you for your help!
Best regards,
Jörg