yellowmat
2nd March 2007, 10:13
Hi everybody,
As explain in the title, I (think I) have a problem with the QWidget::winId() method return value.
I am using mplayer to play movies in my application. I use the -wid argument to tell mplayer into which widget to display. I can hear sound but I can't see the video.
I did the followings tests :
* I try to run, in the command line, mplayer with the name of a movie file as the only argument ... it works fine because a window opens, and I can see the movie
* I try to do the same in my application, adding the -wid argument with the widget id ... I can hear sounds but can't see anything
* I use a specific background color for my widget in order to be sure it is shown when I request mplayer to play the movie ... I can see a square, with the specific background color where the movie (the widget itself) is supposed to be played so the widget is well shown
So, I don't understand why I can't see the movie.
Here is the code of my widget :
.h
#ifndef _WIDGET_VIDEO_H
#define _WIDGET_VIDEO_H
#include <qwidget.h>
class QString;
class QProcess;
class CWidgetVideo : public QWidget
{
public:
CWidgetVideo(QWidget* parent=0, const char* name=0);
~WidgetVideo();
public:
void StartVideo(const QString& video);
void StopVideo();
private:
QProcess* m_pProcessVideo;
};
#endif
.cpp
#include "WidgetVideo.h"
#include <qapplication.h>
#include <qstring.h>
#include <qprocess.h>
CWidgetVideo::CWidgetVideo(QWidget* parent/*=0*/, const char* name/*=0*/):
QWidget(parent, name),
m_pProcessVideo(0)
{
}
CWidgetVideo::~CWidgetVideo()
{
StopVideo();
}
void CWidgetVideo::StartVideo(const QString& video)
{
setBackgroundColor(QColor(255, 0, 255));
if( m_pProcessVideo )
StopVideo();
m_pProcessVideo = new QProcess( this );
m_pProcessVideo->addArgument("C:\\MPLAYER\\mplayer.exe");
m_pProcessVideo->addArgument("-wid");
m_pProcessVideo->addArgument(QString::number((int)winId()));
m_pProcessVideo->addArgument(video);
if( !m_pProcessVideo->start() )
qDebug("Impossible to start");
}
void CWidgetVideo::StopVideo()
{
if( m_pProcessVideo )
{
m_pProcessVideo->tryTerminate();
delete m_pProcessVideo;
m_pProcessVideo = 0;
}
}
Finally the main application source code :
void TestMPlayerDialog::init()
{
m_pPlayer = 0;
}
void TestMPlayerDialog::starting()
{
QString directory = QDir::currentDirPath() + "/";
QString video = QFileDialog::getOpenFileName(directory, "Video (*.avi *.wmv *.mpeg *.mov)", this, "", "");
if( video != "" )
{
if( m_pPlayer )
{
delete m_pPlayer;
m_pPlayer = 0;
}
m_pPlayer = new CWidgetVideo(this, "Player");
m_pPlayer->setGeometry(10, 120, 320, 240);
m_pPlayer->StartVideo(video);
m_pPlayer->show();
}
}
void TestMPlayerDialog::stopping()
{
if( m_pPlayer )
{
m_pPlayer->StopVideo();
m_pPlayer->hide();
delete m_pPlayer;
m_pPlayer = 0;
}
}
starting and stopping are two slots called when buttons start and stop are pressed.
I hope someone could help me, thantks in advance.
As explain in the title, I (think I) have a problem with the QWidget::winId() method return value.
I am using mplayer to play movies in my application. I use the -wid argument to tell mplayer into which widget to display. I can hear sound but I can't see the video.
I did the followings tests :
* I try to run, in the command line, mplayer with the name of a movie file as the only argument ... it works fine because a window opens, and I can see the movie
* I try to do the same in my application, adding the -wid argument with the widget id ... I can hear sounds but can't see anything
* I use a specific background color for my widget in order to be sure it is shown when I request mplayer to play the movie ... I can see a square, with the specific background color where the movie (the widget itself) is supposed to be played so the widget is well shown
So, I don't understand why I can't see the movie.
Here is the code of my widget :
.h
#ifndef _WIDGET_VIDEO_H
#define _WIDGET_VIDEO_H
#include <qwidget.h>
class QString;
class QProcess;
class CWidgetVideo : public QWidget
{
public:
CWidgetVideo(QWidget* parent=0, const char* name=0);
~WidgetVideo();
public:
void StartVideo(const QString& video);
void StopVideo();
private:
QProcess* m_pProcessVideo;
};
#endif
.cpp
#include "WidgetVideo.h"
#include <qapplication.h>
#include <qstring.h>
#include <qprocess.h>
CWidgetVideo::CWidgetVideo(QWidget* parent/*=0*/, const char* name/*=0*/):
QWidget(parent, name),
m_pProcessVideo(0)
{
}
CWidgetVideo::~CWidgetVideo()
{
StopVideo();
}
void CWidgetVideo::StartVideo(const QString& video)
{
setBackgroundColor(QColor(255, 0, 255));
if( m_pProcessVideo )
StopVideo();
m_pProcessVideo = new QProcess( this );
m_pProcessVideo->addArgument("C:\\MPLAYER\\mplayer.exe");
m_pProcessVideo->addArgument("-wid");
m_pProcessVideo->addArgument(QString::number((int)winId()));
m_pProcessVideo->addArgument(video);
if( !m_pProcessVideo->start() )
qDebug("Impossible to start");
}
void CWidgetVideo::StopVideo()
{
if( m_pProcessVideo )
{
m_pProcessVideo->tryTerminate();
delete m_pProcessVideo;
m_pProcessVideo = 0;
}
}
Finally the main application source code :
void TestMPlayerDialog::init()
{
m_pPlayer = 0;
}
void TestMPlayerDialog::starting()
{
QString directory = QDir::currentDirPath() + "/";
QString video = QFileDialog::getOpenFileName(directory, "Video (*.avi *.wmv *.mpeg *.mov)", this, "", "");
if( video != "" )
{
if( m_pPlayer )
{
delete m_pPlayer;
m_pPlayer = 0;
}
m_pPlayer = new CWidgetVideo(this, "Player");
m_pPlayer->setGeometry(10, 120, 320, 240);
m_pPlayer->StartVideo(video);
m_pPlayer->show();
}
}
void TestMPlayerDialog::stopping()
{
if( m_pPlayer )
{
m_pPlayer->StopVideo();
m_pPlayer->hide();
delete m_pPlayer;
m_pPlayer = 0;
}
}
starting and stopping are two slots called when buttons start and stop are pressed.
I hope someone could help me, thantks in advance.