Skip to content

Commit 58908e5

Browse files
committed
chore(qt)[sc-97670]: stop using deprecated QMediaPlayer functions
1 parent 08153a0 commit 58908e5

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/Test/VideoTest.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "VideoTest.h"
2121
#include <string>
22+
#include <QtMultimedia/QMediaMetaData>
2223

2324
std::string testDataFolder;
2425

@@ -28,7 +29,11 @@ VideoTestWidget::VideoTestWidget(QWidget *parent) :
2829
this->setGeometry(0, 0, 600, 400);
2930
this->setMinimumSize(400, 400);
3031
this->setMaximumSize(800, 800);
32+
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
33+
mediaPlayer = new QMediaPlayer(NULL);
34+
#else
3135
mediaPlayer = new QMediaPlayer(NULL, QMediaPlayer::VideoSurface);
36+
#endif
3237
videoWidget = new QVideoWidget();
3338
videoWidget->setObjectName("videoPlayer");
3439

@@ -73,12 +78,22 @@ VideoTestWidget::VideoTestWidget(QWidget *parent) :
7378

7479
QUrl videoUrl = QUrl::fromLocalFile(videoPath);
7580
if (!videoUrl.isEmpty() && videoUrl.isValid()) {
81+
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
82+
mediaPlayer->setSource(videoUrl);
83+
#else
7684
mediaPlayer->setMedia(videoUrl);
85+
#endif
7786
durationChanged(mediaPlayer->duration());
7887
positionChanged(mediaPlayer->position());
88+
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
7989
volumeChanged(mediaPlayer->volume());
90+
#endif
8091
playButton->setEnabled(true);
92+
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
93+
QSize resolution = mediaPlayer->metaData()[QMediaMetaData::Resolution].toSize();
94+
#else
8195
QSize resolution = mediaPlayer->media().canonicalResource().resolution();
96+
#endif
8297
this->setGeometry(0,0, resolution.width(), resolution.height());
8398
}
8499

@@ -92,7 +107,11 @@ VideoTestWidget::~VideoTestWidget()
92107

93108
void VideoTestWidget::play()
94109
{
110+
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
111+
if(mediaPlayer->playbackState() == QMediaPlayer::PlayingState){
112+
#else
95113
if(mediaPlayer->state() == QMediaPlayer::PlayingState){
114+
#endif
96115
mediaPlayer->pause();
97116
playButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
98117
} else {
@@ -101,10 +120,12 @@ void VideoTestWidget::play()
101120
}
102121
}
103122

123+
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
104124
void VideoTestWidget::setVolume(int volume)
105125
{
106126
mediaPlayer->setVolume(volume);
107127
}
128+
#endif
108129

109130
void VideoTestWidget::setPlayingPosition(int pos)
110131
{

0 commit comments

Comments
 (0)