This is probably a very noob question... I am very new to Qt, and trying programming in Qt creator. Now I created a new Qt Widgets Application from Qt creator, and want to play a video with it. I now have the following 6 files in my project:
Where and how exactly should I write my code to make it play Demo.mp4 when I run my application (maybe using some tools called QVideoPlayer)? Should I add some Qwidget onto my videoplayer.ui? I now have four buttons "play", "pause", "full_screen" and "rearrange" on my videoplayer.ui. The result I want is something with features of:
You are looking for Qt Multimedia Widgets. (You might need to install extra packages when running Linux).
The basic idea goes like this:
QVideoWidget
. This is where the video is displayed.
.ui
file.fullScreen
property.QMediaPlayer
which controls what is played and when it's played.
QMediaPlayer::setVideoOutput(yourVideoWidgetGoesHere);
.QMediaPlaylist
to your QMediaPlayer
.QMediaPlayer::play()
and you should be good to goThen you want some basic controls if this works so far. QMediaPlayer
provides the following slots that exactly do as their names suggest:
pause()
play()
stop()
setPosition(int)
, argument is in milliseconds. duration()
might be of interest.setVolume(int)
and setMuted(bool)
. Volume goes from 0 to 100.setPlaybackRate(double)
metaData(QString key)
: http://qt-project.org/doc/qt-5/qmediaobject.html#metaDataEach of these also has a corresponding change signal, very interesting for you is probably the positionChanged(int)
signal to update a slider or something similar with the current position.
Basic example courtesy of the Qt documentation:
player = new QMediaPlayer;
playlist = new QMediaPlaylist(player);
playlist->addMedia(QUrl("http://example.com/myclip1.mp4"));
playlist->addMedia(QUrl("http://example.com/myclip2.mp4"));
videoWidget = new QVideoWidget;
player->setVideoOutput(videoWidget);
videoWidget->show();
playlist->setCurrentIndex(1);
player->play();