PDA

View Full Version : How to get Phonon::VideoPlayer video size



Seishin
17th July 2012, 22:36
Hi everyone,

I'm back with a new question.
I have a dialog box which has a button to call QFileDialog::getOpenFileName() to choose a video file.
And the Phonon::VideoPlayer will use the path to play the video.
Now I want to get the width and height of the video. After some searching I try to use VideoPlayer->sizeHint() to get the size while the path is set. The code is like:


void VideoDialog::addVideo() // A slot called by clicked() signal of the button
{
QMessageBox::warning(this, tr("0"), QString::number(m_videoPlayer->sizeHint().width()) + " x " + QString::number(m_videoPlayer->sizeHint().height()));
QString videoFile = QFileDialog::getOpenFileName(.....); // The function arguments are removed
if(!videoFile.isEmpty()){
m_videoPlayer->mediaObject()->clear();
m_videoPlayer->mediaObject()->setCurrentSource(videoFile);
QMessageBox::warning(this, tr("1"), QString::number(m_videoPlayer->sizeHint().width()) + " x " + QString::number(m_videoPlayer->sizeHint().height()));
}
}

The problem I met is that after I set the video path, the sizeHint is not updated. But if I press the button again, the sizeHint will be the right value. Is there a way to get the sizeHint immediately?
Thanks in advance.

Seishin
18th July 2012, 16:00
And another thing I found is when I hide the VideoPlayer widget, I only get 1 x 1 every time on sizeHint.
I know the doc says "The default implementation of sizeHint() returns an invalid size if there is no layout for this widget. "
But I do need to hide the widget on initial. Any help please?

Seishin
20th July 2012, 21:09
Please ignore my last reply, I think it is caused by I didn't load the video first.

So Back to my original question, after I load my video, I cannot get the size directly.
I solved it by getting size after the hasVideoChanged() signal.

Now I can get the size of the 1st video. But if I change it to another video, even if the hasVideoChanged() signal is emitted, the video player's sizeHint is keeping the old value.
I can solve it by doing

videoPlayer->show();
videoPlayer->sizeHint();
videoPlayer->hide();
But obviously that's not a good way since I want the player keeping hidden.
This there a way to solve this?
Thanks.