PDA

View Full Version : VideoWidget problem



baluk
23rd October 2010, 13:42
Hi,

I am using videoWidget to play a video file. But i want to play a video with original aspect ration which means i have to set videoWidget::AspectrationAuto property. But when I play with original aspect ration the video is played in the middle of the videowidget and the rest (upper and bottom side) is seen as a black screen. I can't set the videowidget screen size to the original video frame size. I would be thankful for any suggestions.

Thank You,
Baluk

wysota
23rd October 2010, 13:46
Is the video widget in a layout? If so, set its SizePolicy to Fixed/Fixed, that should be enough.

baluk
23rd October 2010, 14:05
Thanks for the reply. I am getting some syntax errors when setting QSizePolicy. Here I am copying my code can please check whats wrong.



QSizePolicy policy = new QSizePolicy();
policy.setHorizontalPolicy(QSizePolicy::Fixed);
policy.setVerticalPolicy(QSizePolicy::Fixed);
videoWidget->setSizePolicy(policy);


Thank You,
baluk

wysota
23rd October 2010, 14:06
Obviously the first line is wrong, it should be:

QSizePolicy policy;

baluk
23rd October 2010, 14:18
I still can't rid of the main problem. I have 3 QFrames and I applied grid layout to all. And I used one frame for video play. QSizePolicy doesn't solve the problem.

wysota
23rd October 2010, 14:31
Please show us some code reproducing the problem. Just please don't post your whole application.

baluk
23rd October 2010, 14:38
Sure.


MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);


this->mediaObject = new Phonon::MediaObject(this);
this->audioOutput = new Phonon::AudioOutput(Phonon::VideoCategory,this);
Phonon::createPath(mediaObject, audioOutput);
Phonon::VideoWidget *videoWidget = new Phonon::VideoWidget(ui->frame);

QSizePolicy policy;
policy.setHorizontalPolicy(QSizePolicy::Fixed);
policy.setVerticalPolicy(QSizePolicy::Fixed);
videoWidget->setSizePolicy(policy);
videoWidget->setAspectRatio(Phonon::VideoWidget::AspectRatioAut o);

Phonon::createPath(mediaObject, videoWidget);
QUrl url("output_1.avi");

mediaObject->setCurrentSource(url);
mediaObject->setTickInterval(1000);

connect(mediaObject, SIGNAL(finished()), mediaObject, SLOT(deleteLater()));
connect(ui->pause,SIGNAL(clicked()),mediaObject,SLOT(pause())) ;
connect(ui->play,SIGNAL(clicked()),mediaObject,SLOT(play()));
connect(ui->stop,SIGNAL(clicked()),mediaObject,SLOT(stop()));
}


Thank You,

Baluk

wysota
23rd October 2010, 14:58
Looks like someone forgot to put the video widget in a layout.

baluk
23rd October 2010, 15:15
Yes. Now I applied the layout.



QHBoxLayout *hVideo = new QHBoxLayout(ui->frame);
hVideo->addWidget(videoWidget);


But still the same result. I am attaching the image of my app output. So you can have a clear picture.

Thank You,
Baluk

wysota
23rd October 2010, 15:54
What does sizeHint() of the video widget return during playback? Note, you have to query for it during playback, it won't return proper value otherwise.

baluk
23rd October 2010, 16:17
oke. I did query the sizeHint(), it returns the QSize(640, 480). But its the same value returned for every video. What I thought is, it was returning the player(widget) size but not the video file size. I am not sure.

wysota
23rd October 2010, 16:27
When do you query for the sizeHint()? Please show us the code.

baluk
23rd October 2010, 16:50
Sure. Here it is



MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);


this->mediaObject = new Phonon::MediaObject(this);
this->audioOutput = new Phonon::AudioOutput(Phonon::VideoCategory,this);
Phonon::createPath(mediaObject, audioOutput);
Phonon::VideoWidget *videoWidget = new Phonon::VideoWidget(ui->frame);
QHBoxLayout *hVideo = new QHBoxLayout(ui->frame);
hVideo->addWidget(videoWidget);
QSizePolicy policy;
policy.setHorizontalPolicy(QSizePolicy::Fixed);
policy.setVerticalPolicy(QSizePolicy::Fixed);
videoWidget->setSizePolicy(policy);
videoWidget->setAspectRatio(Phonon::VideoWidget::AspectRatioAut o);
QSize size= videoWidget->sizeHint();
videoWidget->setFixedSize(size);
qDebug() << size;
Phonon::createPath(mediaObject, videoWidget);
QUrl url("output_1.avi");
mediaObject->setCurrentSource(url);

mediaObject->setTickInterval(1000);

connect(mediaObject, SIGNAL(finished()), mediaObject, SLOT(deleteLater()));
connect(ui->pause,SIGNAL(clicked()),mediaObject,SLOT(pause())) ;
connect(ui->play,SIGNAL(clicked()),mediaObject,SLOT(play()));
connect(ui->stop,SIGNAL(clicked()),mediaObject,SLOT(stop()));
}

wysota
23rd October 2010, 17:14
Let me repeat - query for the sizeHint() after the video starts playing. By the way, your code doesn't work because you set a fixed size on the video widget so how do you expect it to resize to proper size?

baluk
23rd October 2010, 18:00
Hi wysota you are right. It seems working fine now. I am getting desired output. Thank you very much for your help and sorry for my many questions :).

wysota
24th October 2010, 02:32
No problem, we are here to help.