Qt Video Playback in Qt 5


Example

Let's create very simple video player using QtMultimedia module of Qt 5.

In .pro file of your application you will need the following lines:

QT += multimedia multimediawidgets

Note that multimediawidgets is necessary for usage of QVideoWidget.

#include <QtMultimedia/QMediaPlayer>
#include <QtMultimedia/QMediaPlaylist>
#include <QtMultimediaWidgets/QVideoWidget>

QMediaPlayer *player;
QVideoWidget *videoWidget;
QMediaPlaylist *playlist;

player = new QMediaPlayer;

playlist = new QMediaPlaylist(player);
playlist->addMedia(QUrl::fromLocalFile("actualPathHere"));

videoWidget = new QVideoWidget;
player->setVideoOutput(videoWidget);

videoWidget->show();
player->play();

That's all - after launching the application (if necessary codecs are installed in the system), video file playback will be started.

The same way you can play video from URL in Internet, not just local file.