QMediaPlayer resolution returns (-1x-1)
-
Hi,
I have the following code:
@
QMediaPlayer * Player = new QMediaPlayer(this,QMediaPlayer::StreamPlayback);Player->setMedia(QUrl::fromLocalFile(Filename));
Player->setVideoOutput(Screen);
Player->play();
Screen->show();Screen->setGeometry(0,0,Player->media().canonicalResource().resolution().width(),Player->media().canonicalResource().resolution().height());
@When calling Player->media().canonicalResource().resolution().width() for example, it returns -1 instead of the video's original width, I tried changing the order of the code lines and calling SIGNALS but that didn't help. I can set the video to the size I want, but I actually want the video to be set to its original sizes when played. (By the way the audio plays with no problems)
So Is that a bug or have I done something wrong?
Best,
MJaoune -
Could you provide a full-working source code with all the includes and so?
Anyway, I think you might be using the wrong class. The "QMediaPlayer":http://qt-project.org/doc/qt-5.1/qtmultimedia/qmediaplayer.html#details class only provides the functionality of a media player, but nothing related to a GUI is actually implemented - so you can get no size out of a non-GUI object (widget). The "QtMultimediaWidgets":http://qt-project.org/doc/qt-5.1/qtmultimediawidgets/qtmultimediawidgets-index.html class (and its derivatives) instead provides GUI widgets - and these can be used to get widget size references.
-
UPDATE: I figured out that the problem is with getting the Metadata of the video, since when using connect with SIGNAL MetaDataChanged(bool) it just returns false, also, when trying to read the resolution manually from the metadata it also returns -1, any help?
-
Hi,
Could you share the link to the bug report ? So others interested in the same problem can find it more easily
-
-
You can get the video's native resolution once the media has loaded.
Say you have a slot called
void handleMediaStatusChange(QMediaPlayer::MediaStatus)@
connect(
&player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),
this, SLOT(handleMediaStatusChange(QMediaPlayer::MediaStatus))
);void YourApp::handleMediaStatusChange(QMediaPlayer::MediaStatus s) {
if ( s == QMediaPlayer::LoadedMedia) {
qDebug() << "native resolution:" << Screen.nativeSize();
qDebug() << "total duration:" << player.duration() << "msec";
}
}
@ -
Hi.
Screen is of type QVideoWidget, and so it doesn't have nativeSize() function.
I tried setting the Screen to QGraphicsVideoItem and then getting the nativeSize but it still returns -1x-1As for the duration, I was able to obtain it after the Media was Loaded successfully.
-
I think I discovered the problem, and its a critical problem...
The problem was using MingW as the compiler... When using VS2012 x64, the media's Meta Data was found and I could get the resolution of the video.
To be more specific, when using MingW, the SIGNAL metaDataAvailableChanged(bool) always returns false, which means it can never find the MetaData of the Media, but when using VS2012, everything works perfectly, including the SIGNAL.
That's a very critic bug and I hope it gets fixed soon since I prefer MingW over VS2012 since MingW is based on GNU's GCC and is cross-platform.
I will open another bug ticket including the new important information, but if anyone still knows a solution, please provide it here so we can help Qt users.
EDIT: Here is the Bug ticket: "https://bugreports.qt-project.org/browse/QTBUG-33888":https://bugreports.qt-project.org/browse/QTBUG-33888
-
You should rather add your findings to the existing bug report since it's related so everything is in only one place. Otherwise it complicates the task for the maintainers to gather all the information to fix it