Question

I'm working on migrating my code from Qt 4.8.4 to Qt 5.1.1 and seemed to have run into a peculiar problem. Previously I was using the Phonon library's video widget to allow users to interact with the video. Since Phonon is no longer supported I was looking for a way to replace my Phonon widget via the Qt Designer but I found no replacement widget available. Does anyone know how we're supposed to go about porting this functionality?

If anyone has any insight, it is appreciated as always!

Was it helpful?

Solution

All the other answers provide very useful information, but since I was looking for a specific and functional implementation, I'm guessing people that stumble on this may be looking for one as well, so I'll post my code along with my thought process and a bit of background info of my setup.

videoWidget = new QVideoWidget;
player = new QMediaPlayer;

verticalLayout->addWidget(videoWidget);

player->setVideoOutput(videoWidget);
player->setMedia(QUrl::fromLocalFile("Resources\\videos\\example.m4v"));
videoWidget->show();
player->play();

So to go through this, basically in my project I have a widget that is a part of a stackwidget structure on which I have some QWidgets like playback control buttons, labels, etc, and I previously had my Phonon video player. I really really didn't want to generate it all programatically so I managed to find a solution.

The above code was located in this container widgets constructor. In the designer I have made a simple, empty verticalLayout, positioned and sized it to my liking. This allowed me to embed the QVideoWidget despite not having a interactive QWidget in the Designer. videoWidget, and player are declared as private in the container widget's header file.

OTHER TIPS

You've already noted there's no more Phonon

Now what you've got is QtMultimedia and the QtMultimediaWidgets. If you want them available to your project and you're using Qmake, then change your QT line in your .pro file from something like:

QT += widgets

to:

QT += widgets multimediawidgets

That won't do anything about the designer interaction, though. I think it's probably a matter of no one having done the work to make a custom widget extension for QVideoWidget.

If that's correct, then if you want to place a QVideoWidget into your form via Qt designer you will have to use "Widget Promotion". Just put an ordinary QWidget into your layout, and then right click on it in the form and pick Promote to ...

As for the specifics of porting Phonon abilities to the new widgets, I dunno what's covered and what isn't. No answers here yet, either:

How to port Qt4.6 Phonon based media-application to Qt 5.1?

It seems that although Qt itself no longer includes Phonon, there is a Qt5 port available as an external library:

Alternatively, you can switch to the new QtMultimedia APIs:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top