aboutsummaryrefslogtreecommitdiff
path: root/src/widgets
diff options
context:
space:
mode:
authorTomas Åkesson <tomas@entropic.se>2023-03-25 19:20:38 +0100
committerFelix Queißner <felix@ib-queissner.de>2023-03-26 01:01:13 +0100
commit84c11ed7669e665863460384cc78a5ed9341552b (patch)
treee007d94b231be27c00040d71014da142cf64f57b /src/widgets
parenta63178f48fe23b0de779ea1988e72e4b128fcb1a (diff)
downloadkristall-84c11ed7669e665863460384cc78a5ed9341552b.tar.gz
Fix media player stuttering
Only call setPosition() on the QMediaPlayer object when the user has manually dragged the slider position slider. Otherwise the slider and player will call each other, probably causing a feedback loop which causes stuttering.
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/mediaplayer.cpp24
-rw-r--r--src/widgets/mediaplayer.hpp5
2 files changed, 27 insertions, 2 deletions
diff --git a/src/widgets/mediaplayer.cpp b/src/widgets/mediaplayer.cpp
index 74551ca..bb0db0b 100644
--- a/src/widgets/mediaplayer.cpp
+++ b/src/widgets/mediaplayer.cpp
@@ -18,7 +18,8 @@ MediaPlayer::MediaPlayer(QWidget *parent) :
QWidget(parent),
ui(new Ui::MediaPlayer),
media_stream(),
- player()
+ player(),
+ manual_seek(false)
{
ui->setupUi(this);
@@ -51,7 +52,9 @@ MediaPlayer::MediaPlayer(QWidget *parent) :
connect(&this->player, &QMediaPlayer::positionChanged, this, &MediaPlayer::on_media_positionChanged);
- connect(this->ui->media_progress, &QSlider::valueChanged, &this->player, &QMediaPlayer::setPosition);
+ connect(this->ui->media_progress, &QSlider::valueChanged, this, &MediaPlayer::on_seekChanged);
+ connect(this->ui->media_progress, &QSlider::sliderPressed, this, &MediaPlayer::on_seekPressed);
+ connect(this->ui->media_progress, &QSlider::sliderReleased, this, &MediaPlayer::on_seekReleased);
}
MediaPlayer::~MediaPlayer()
@@ -132,3 +135,20 @@ void MediaPlayer::on_media_playbackChanged(QMediaPlayer::PlaybackState status)
);
}
#endif
+
+void MediaPlayer::on_seekChanged(qint64 pos)
+{
+ if (this->manual_seek) {
+ player.setPosition(pos);
+ }
+}
+
+void MediaPlayer::on_seekPressed()
+{
+ this->manual_seek = true;
+}
+
+void MediaPlayer::on_seekReleased()
+{
+ this->manual_seek = false;
+}
diff --git a/src/widgets/mediaplayer.hpp b/src/widgets/mediaplayer.hpp
index d7e6699..4c19f70 100644
--- a/src/widgets/mediaplayer.hpp
+++ b/src/widgets/mediaplayer.hpp
@@ -28,6 +28,10 @@ private slots:
void on_mute_button_clicked(bool checked);
+ void on_seekChanged(qint64 pos);
+ void on_seekPressed();
+ void on_seekReleased();
+
private: // slots
void on_media_positionChanged(qint64 pos);
@@ -42,6 +46,7 @@ private:
QBuffer media_stream;
QString mime;
QMediaPlayer player;
+ bool manual_seek;
};
#endif // MEDIAPLAYER_HPP