From b59aa0827e46ccd0be876436013c62d6aef3c21f Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Fri, 7 Apr 2023 02:30:38 +0200 Subject: [PATCH] GstEnginePipeline: Always set initial volume --- src/engine/gstenginepipeline.cpp | 11 ++++++++++- src/engine/gstenginepipeline.h | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/engine/gstenginepipeline.cpp b/src/engine/gstenginepipeline.cpp index 80684bd99..bd7a5af3b 100644 --- a/src/engine/gstenginepipeline.cpp +++ b/src/engine/gstenginepipeline.cpp @@ -99,6 +99,7 @@ GstEnginePipeline::GstEnginePipeline(QObject *parent) pending_seek_nanosec_(-1), last_known_position_ns_(0), next_uri_set_(false), + volume_set_(false), volume_internal_(-1.0), volume_percent_(100), use_fudge_timer_(false), @@ -846,6 +847,8 @@ void GstEnginePipeline::NotifyVolumeCallback(GstElement *element, GParamSpec *pa GstEnginePipeline *instance = reinterpret_cast(self); + if (!instance->volume_set_) return; + g_object_get(G_OBJECT(instance->volume_), "volume", &instance->volume_internal_, nullptr); const uint volume_percent = static_cast(qBound(0L, lround(instance->volume_internal_ / 0.01), 100L)); @@ -1378,6 +1381,9 @@ void GstEnginePipeline::StateChangedMessageReceived(GstMessage *msg) { if (!pipeline_is_initialized_ && (new_state == GST_STATE_PAUSED || new_state == GST_STATE_PLAYING)) { qLog(Debug) << "Pipeline initialized: State changed from" << old_state << "to" << new_state; pipeline_is_initialized_ = true; + if (!volume_set_) { + SetVolume(volume_percent_); + } if (pending_seek_nanosec_ != -1 && pipeline_is_connected_) { QMetaObject::invokeMethod(this, "Seek", Qt::QueuedConnection, Q_ARG(qint64, pending_seek_nanosec_)); } @@ -1489,9 +1495,12 @@ void GstEnginePipeline::SetVolume(const uint volume_percent) { if (volume_) { const double volume_internal = static_cast(volume_percent) * 0.01; - if (volume_internal != volume_internal_) { + if (!volume_set_ || volume_internal != volume_internal_) { volume_internal_ = volume_internal; g_object_set(G_OBJECT(volume_), "volume", volume_internal, nullptr); + if (pipeline_is_initialized_) { + volume_set_ = true; + } } } diff --git a/src/engine/gstenginepipeline.h b/src/engine/gstenginepipeline.h index ad1b9adaa..47a989f88 100644 --- a/src/engine/gstenginepipeline.h +++ b/src/engine/gstenginepipeline.h @@ -277,6 +277,7 @@ class GstEnginePipeline : public QObject { // Complete the transition to the next song when it starts playing bool next_uri_set_; + bool volume_set_; gdouble volume_internal_; uint volume_percent_;