Tuesday, February 9th 2010, 10:19am UTC

You are not logged in.

  • Login
  • Register

Rajesh

Beginner

Posts: 6

Location: Chennai

1

Monday, March 27th 2006, 12:55pm

launching mplayer using qt

Hi
I need to launch/run mplayer through my qt application.
Can anybody help me with this.
I actually need to run mplayer with a specific mov file (mpeg/avi) on the click of a button in my qt forms, can anyone pls let me know how do I go abt this.
  • Go to the top of the page

tizianotizi

Beginner

Posts: 16

Location: Italy

2

Tuesday, March 28th 2006, 6:19pm

In the header file put
QProcess *mplayer_proc;
then in the implementation:

void app::play(QString fn)

mplayer_proc = new QProcess( this );
connect( mplayer_proc, SIGNAL( processExited() ), this, SLOT( exitedMPlayer() ) );
connect( mplayer_proc, SIGNAL( wroteToStdin () ), this, SLOT( wroteToStdinMPlayer() ) );
connect( mplayer_proc, SIGNAL( readyReadStderr () ), this, SLOT( readyReadStderrMPlayer() ) );
connect( mplayer_proc, SIGNAL( readyReadStdout() ), this, SLOT( readStdoutMPlayer() ) );
mplayer_proc->clearArguments();
mplayer_proc->addArgument( "mplayer" );
mplayer_proc->addArgument( "-nomouseinput" );
mplayer_proc->addArgument( "-wid" );
WId wind = videoWin->winId(); //a control that contains mplayer
long windowid = long( wind );
mplayer_proc->addArgument( QString( "%1" ).arg( windowid, 0, 10 ) );
mplayer_proc->addArgument( "-slave" );
mplayer_proc->addArgument( "-dr" ); //direct rendering
mplayer_proc->addArgument( "-nodouble" ); // no double buffering because direct rendering is enabled
mplayer_proc->addArgument( "-nojoystick" );
mplayer_proc->addArgument( "-nolirc" );
mplayer_proc->addArgument( "-idx" );
mplayer_proc->addArgument( "-vo" );
mplayer_proc->addArgument( "xv" );
mplayer_proc->addArgument( fn );// the file name you want to play (with path)

//qDebug(QString("%1").arg(windowid,0,10));
// QStringList list = mplayer_proc->arguments();
// QStringList::Iterator it = list.begin();
// while ( it != list.end() )
// {
// qDebug ( *it );
// ++it;
// }


void app::exitedMPlayer()
{
qDebug( "MPlayer exited." );
}


void app::readStdoutMPlayer()
{
QString out;
bool line = mplayer_proc->canReadLineStdout ();
if ( line == false )
{
QByteArray ba;
ba = mplayer_proc->readStdout();
QString s = QString( ba );
qDebug(s + "\n");
// int f = s.findRev( "Genero indice:", -1, false );
// if ( f == -1 ) f = s.findRev( "Generating Index:", -1, false );
// if ( f > -1 )
// {
// s = s.right( s.length() - f );
// txt_status->setText( s );
// }
// qDebug("canReadLineStdout () == false");
}
else // canReadLineStdout () == true
{
out = mplayer_proc->readLineStdout ();
qDebug(out);
//videoLength
if ( out.left( 12 ) == "Movie-Aspect" )
{
// qDebug( out );
if ( out.find( "ANS_LENGTH", 0, false ) > -1 )
{
}
if ( out.find( "ANS_PERCENT_POSITION", 0, false ) > -1 )
{
}
if ( out.find( "ANS_TIME_POSITION", 0, false ) > -1 )
{
}
if ( out.left( 6 ) == "VIDEO:" )
{
}
if ( out.left( 6 ) == "AUDIO:" )
{
}
}
}
  • Go to the top of the page

tizianotizi

Beginner

Posts: 16

Location: Italy

3

Tuesday, March 28th 2006, 6:43pm

I correct the previous message:

void app::play(QString fn)
{
mplayer_proc = new QProcess( this );
connect( mplayer_proc, SIGNAL( processExited() ), this, SLOT( exitedMPlayer() ) );
.....
.....
mplayer_proc->addArgument( "xv" );
mplayer_proc->addArgument( fn );// the file name you want to play (with path)
mplayer_proc->start();
}
  • Go to the top of the page

Rajesh

Beginner

Posts: 6

Location: Chennai

4

Wednesday, March 29th 2006, 5:39am

thnks

thnks tizi
will try tht out and let u knw
  • Go to the top of the page

Dinesh

Beginner

Posts: 14

Location: Mumbai

5

Monday, April 3rd 2006, 7:59am

RE: launching mplayer using qt

Hi,
I am trying to write media player code using QMovie class.
But this can not play movie(only .mng). Wat should i do so that it can play movie(mpeg,avi) ?
Thank u in advance.
  • Go to the top of the page

Dinesh

Beginner

Posts: 14

Location: Mumbai

6

Monday, April 3rd 2006, 10:12am

RE: launching mplayer using qt(plz help me)

Hi Rajesh,
I m Dinesh.
I have written a code where i used QMovie class and as far as Qt-trolltech's documntation is concern the program should play movie.
But it cant. it only can show still picture and .mng file.
thats all.
I m not getting wat to do next.
I have added the code which u have been sent by someone using QProcess.
But still not getting success.
The probem with the new code is
1)addArgument is not a member function of QProcess
2)clearArgument is not a member function of QProcess.
And so on......
can u plz help me out here and can u plz send the code so that i can compare it with my code.
If u want then i will send u my (using QMovie) code.
ok.
thanks.
plz do reply and help me.
  • Go to the top of the page

tizianotizi

Beginner

Posts: 16

Location: Italy

7

Monday, April 3rd 2006, 4:45pm

Have you included the header?
#include <qprocess.h>
  • Go to the top of the page

Dinesh

Beginner

Posts: 14

Location: Mumbai

8

Tuesday, April 4th 2006, 4:55am

ya i have included the header file <QProcess.h>
but it i not running?
plz help??
  • Go to the top of the page

Dinesh

Beginner

Posts: 14

Location: Mumbai

9

Tuesday, April 4th 2006, 6:00am

I m new in this field.
can u plz help me?
As far as trolltech site is concern it is saying that QMovie class can play vedio. But in my case it can only play .mng format.
How to proceed? I m sending u my code:-
I m sending u the cpp file only:-
plz help:-

#include <idle.h>
#include <QtGui>
#include <QWidget>
#include<QDate>
//#include <QIODevice>
//#include <QByteArray>

QString str;
QMainWindow *MainWindow;
QFrame *frmidle;
QString fileName;

void Idle::setupUi()
{
MainWindow = new QMainWindow();
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
MainWindow->resize(QSize(265, 320).expandedTo(MainWindow->minimumSizeHint()));



frmidle = new QFrame(MainWindow);
frmidle->setObjectName(QString::fromUtf8("frmidle"));
frmidle->setGeometry(QRect(0, 0, 265, 320));
frmidle->setContextMenuPolicy(Qt::ActionsContextMenu);
frmidle->setAutoFillBackground(true);
frmidle->setFrameShape(QFrame::StyledPanel);
frmidle->setFrameShadow(QFrame::Raised);


movie = new QMovie(frmidle);
//movie = new QMovie ( 0, QMovie::supportedFormats (), frmidle);

movie->setCacheMode(QMovie::CacheAll);

movieLabel = new QLabel(frmidle);
movieLabel->setAlignment(Qt::AlignCenter);
movieLabel->setSizePolicy(QSizePolicy::Ignored, SizePolicy::Ignored);
movieLabel->setBackgroundRole(QPalette::Dark);
movieLabel->setAutoFillBackground(true);
movie->setScaledSize(QSize(200, 420));
movieLabel->setGeometry(QRect(0, 0, 265, 250));
//currentMovieDirectory = "movies";
createButtons();

/*actionmenu = new QAction(MainWindow);
actionmenu->setShortcut(Qt::Key_F);
frmidle->addAction(actionmenu);
*/


connect(movie, SIGNAL(stateChanged(QMovie::MovieState)),
this, SLOT(updateButtons()));

updateButtons();

setWindowTitle(tr("Movie Player"));
//resize(265, 320);

Qt::WindowFlags flags = 0;
flags |= Qt::FramelessWindowHint;
MainWindow->setWindowFlags(flags);

MainWindow->show();

//QObject::connect(actionmenu, SIGNAL(triggered()), frmidle, SLOT(hide()));
//QObject::connect(actionmenu, SIGNAL(triggered()), this, SLOT(showGrid()));

actionmenu = new QAction(MainWindow);
actionmenu->setShortcut(Qt::Key_F);
frmidle->addAction(actionmenu);
QObject::connect(actionmenu, SIGNAL(triggered()), this, SLOT(showGrid()));

actionback = new QAction(MainWindow);
actionback->setShortcut(Qt::Key_Backspace);
frmidle->addAction(actionback);

QObject::connect(actionback, SIGNAL(triggered()), this, SLOT(showMain()));

QMetaObject::connectSlotsByName(MainWindow);
} // setupUi

void Idle::open()
{

fileName = QFileDialog::getOpenFileName(this, tr("Open a Movie"),
"..//..");
if (!fileName.isEmpty()) {
currentMovieDirectory = QFileInfo(fileName).path();

movie->stop();
movieLabel->setScaledContents(true);
movie->setFileName(fileName);
movieLabel->setMovie(movie);

str=fileName;
//QApplication::focusWidget() == this;
movie->start();
updateButtons();

QApplication::focusWidget() == frmidle;
//setfocus();
//frmidle->setFocus();
//frmidle->isActiveWindow();
}
}

/*void Idle::setfocus()
{

actionmenu = new QAction(MainWindow);
actionmenu->setShortcut(Qt::Key_F);
frmidle->addAction(actionmenu);
QObject::connect(actionmenu, SIGNAL(triggered()), this, SLOT(showGrid()));


}*/

void Idle::updateButtons()
{
//playButton->setEnabled(movie->isValid() && movie->frameCount() != 1
//frmidle->setFocus(); // && movie->state() == QMovie::NotRunning);
openButton->setEnabled(true);
pauseButton->setEnabled(true);
stopButton->setEnabled(true);

//pauseButton->setChecked(movie->state() == QMovie::Paused);
//playButton->setChecked();
// stopButton->setEnabled(movie->state() != QMovie::NotRunning);
}

void Idle::stop()
{
if (!fileName.isEmpty()) {
currentMovieDirectory = QFileInfo(fileName).path();
movie->stop();
movieLabel->setScaledContents(true);
movieLabel->setMovie(movie);
movie->setFileName(fileName);
str=fileName;
//QApplication::focusWidget() == this;
movie->start();
movie->setPaused(true);
updateButtons();
//QApplication::focusWidget() == frmidle;
//setfocus();
pauseButton->setText(QApplication::translate("", "Play", 0, QApplication::UnicodeUTF8));
stopButton->setDisabled(true);
}
//pauseButton->setEnabled(true);
}

void Idle::pause(bool status)
{
if(movie->state()== QMovie::NotRunning)
{
//movie->start();

}
else
{
if(movie->state()!= QMovie::Paused)
{
movie->setPaused(true);
pauseButton->setText(QApplication::translate("", "Play", 0, QApplication::UnicodeUTF8));
}


else
{
movie->setPaused(false);
pauseButton->setText(QApplication::translate("", "Pause", 0, QApplication::UnicodeUTF8));
}

}
updateButtons();

}

void Idle::createButtons()
{
QSize iconSize(36, 36);
frmbuttons = new QFrame(frmidle);
frmbuttons->setObjectName(QString::fromUtf8("frmbuttons"));
frmbuttons->setGeometry(QRect(0, 250, 265, 70));
frmbuttons->setContextMenuPolicy(Qt::ActionsContextMenu);
frmbuttons->setAutoFillBackground(true);
frmbuttons->setFrameShape(QFrame::StyledPanel);
frmbuttons->setFrameShadow(QFrame::Raised);

openButton = new QPushButton(frmbuttons);

//btnlblopen=new QLabel(openButton);
//openButton->setIcon(QIcon("D:\\Shonima\\video\\images\\MyBaby.bmp"));
openButton->setIconSize(iconSize);


// btnlblopen->setText("Open File");
openButton->setText(QApplication::translate("", "Open", 0, QApplication::UnicodeUTF8));
openButton->setGeometry(QRect(10,20,38, 36));
connect(openButton, SIGNAL(clicked()), this, SLOT(open()));

//connect(pauseButton, SIGNAL(clicked()), this, SLOT(updateButtons()));
//connect(stopButton, SIGNAL(clicked()), this, SLOT(updateButtons()));
/*playButton = new QPushButton(frmidle);
//btnlblplay=new QLabel(playButton);
//playButton->setIcon(QIcon("D:\\Shonima\\video\\images\\vl_diaalert.bmp"));
playButton->setIconSize(iconSize);
playButton->setToolTip(tr("Play"));
//btnlblplay->setText("Play");
//btnlblopen->setGeometry(QRect(20, 20, 20, 20));
playButton->setText(QApplication::translate("", "Play", 0, QApplication::UnicodeUTF8));
playButton->setGeometry(QRect(60,270,40, 36));
connect(playButton, SIGNAL(clicked()), movie, SLOT(start()));
*/
pauseButton = new QPushButton(frmbuttons);
//btnlblpause=new QLabel(pauseButton);
//pauseButton->setCheckable(true);
//pauseButton->setIcon(QIcon("D:\\Shonima\\video\\images\\silence.bmp"));
pauseButton->setIconSize(iconSize);

//btnlblpause->setText("Pause");

pauseButton->setText(QApplication::translate("", "Pause", 0, QApplication::UnicodeUTF8));
pauseButton->setGeometry(QRect(70, 20,65, 36));
//connect(pauseButton, SIGNAL(clicked(bool)), movie, SLOT(setPaused(bool)));


connect(pauseButton, SIGNAL(clicked(bool)), this, SLOT(pause(bool)));


stopButton = new QPushButton(frmbuttons);
//btnlblstop=new QLabel(stopButton);
//stopButton->setIcon(QIcon("D:\\Shonima\\video\\images\\vl_diaerror.bmp"));
stopButton->setIconSize(iconSize);

//btnlblstop->setText("Stop");

stopButton->setText(QApplication::translate("", "Stop", 0, QApplication::UnicodeUTF8));
stopButton->setGeometry(QRect(150, 20,40, 36));
//connect(stopButton, SIGNAL(clicked()), movie, SLOT(stop()));
connect(stopButton, SIGNAL(clicked()), this, SLOT(stop()));

quitButton = new QPushButton(frmbuttons);
//btnlblquit=new QLabel(quitButton);
//quitButton->setIcon(QIcon("D:\\Shonima\\video\\images\\vl_navigation_hint_no_arrows.bmp"));
quitButton->setIconSize(iconSize);

//btnlblquit->setText("Quit");


//stopButton->setEnabled(false);

quitButton->setText(QApplication::translate("", "Quit", 0, QApplication::UnicodeUTF8));
quitButton->setGeometry(QRect(200, 20,40, 36));
//frmbuttons->show();
connect(quitButton, SIGNAL(clicked()), MainWindow, SLOT(close()));
}

void Idle::showGrid()
{
movieLabel->setGeometry(QRect(0, 0, 265, 320));
movie->setScaledSize(QSize(265, 320));
frmbuttons->hide();
}

void Idle::showMain()
{
movieLabel->setGeometry(QRect(0, 0, 265, 250));
movie->setScaledSize(QSize(200, 420));
frmbuttons->show();
}
  • Go to the top of the page

tizianotizi

Beginner

Posts: 16

Location: Italy

10

Friday, April 7th 2006, 4:03pm

I use qt 3 and in qt 4 qprocess has changed.
So if you use qt4 addArgument isn't in QProcess class and you must change addArgument with the new methods of qt4.
  • Go to the top of the page

11

Saturday, May 27th 2006, 8:10pm

Hello to all.
I'm using the code of tizianotizi in order to laungh successfully mplayer within my QT/c++ application. But i want also to be able to get the current playing time (or position), in either milliseconds and frames, from mplayer. Does anyone know how can i do that?
  • Go to the top of the page

grzywacz

Beginner

Posts: 9

Location: Lodz, Poland

Occupation: Student

12

Sunday, May 28th 2006, 11:34pm

Look at the -slave switch in mplayer's manual.
Kind regards,
Karol "grzywacz" Nowak
  • Go to the top of the page

13

Sunday, May 28th 2006, 11:53pm

Thank you for the reply.
I have already tried that. In the -slave mode of mplayer the command the function get_time_pos does not return anything at all.
  • Go to the top of the page

14

Sunday, June 25th 2006, 2:17pm

WId wind = videoWin->winId(); //a control that contains mplayer
long windowid = long( wind );

who can tell me what's the videoWin?// videoWin==this?
  • Go to the top of the page

15

Sunday, June 25th 2006, 2:27pm

how to write function wroteToStdinMPlayer()
  • Go to the top of the page

16

Thursday, February 22nd 2007, 9:47pm

Guys,

I tried tizianotizi’s code from above with Qt 4 and VS 2005 and because of new QProcess /BTW I tried with Q3Process too/ I did not succeed to embedded MPlayer into QWidget or something.
When I use mplayer_proc->addArgument( "-wid" ) – the form is empty when I use mplayer_proc->addArgument( "wid" ); the is MPlayer but in its own window.
Can give me any idea how to fix it. I know that this KDE area but somebody can have info.

Cheers,

Julian
  • Go to the top of the page

17

Friday, June 1st 2007, 2:50am

Hi , is there anybody still care about the problem wid like upstairs?
  • Go to the top of the page

Rate this thread