diff --git a/src/qml/volumefeedback.h b/src/qml/volumefeedback.h --- a/src/qml/volumefeedback.h +++ b/src/qml/volumefeedback.h @@ -24,6 +24,7 @@ #include #include +#include class VolumeFeedback : public QObject { @@ -38,6 +39,9 @@ public Q_SLOTS: void play(quint32 sinkIndex); + +private: + QTime* timer; }; #endif // VOLUMEFEEDBACK_H diff --git a/src/qml/volumefeedback.cpp b/src/qml/volumefeedback.cpp --- a/src/qml/volumefeedback.cpp +++ b/src/qml/volumefeedback.cpp @@ -29,6 +29,9 @@ if (ca_context_set_driver(QPulseAudio::CanberraContext::instance()->canberra(), "pulse") < 0) { return; } + + timer = new QTime(); + timer->start(); } VolumeFeedback::~VolumeFeedback() @@ -49,6 +52,11 @@ return; } + // if the sound was played less than 50 milliseconds ago, we avoing stopping it + // or playing it again so the audio doesn't garble + if(timer->elapsed() < 50) + return; + int playing = 0; const int cindex = 2; // Note "2" is simply the index we've picked. It's somewhat irrelevant. ca_context_playing(context, cindex, &playing); @@ -75,5 +83,7 @@ nullptr ); + timer->start(); + ca_context_change_device(context, nullptr); }