Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved QMediaplayer randomly plays part of the audio in a loop

    General and Desktop
    qmediaplayer audio glitch loop
    1
    3
    274
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      Andrey Vasilyev last edited by Andrey Vasilyev

      Hello!
      I ran into an unexpected problem while using QMediplayer. Sometimes, when receiving a signal "play", the player starts to play a part of the audio file in a loop for a while . I have not been able to figure out what exactly affects this.
      I also added the logging on the call of the signal to play, and I am sure that this signal comes only once.

      I tried moving both QMediplayer instances to separate threads, but that didn't solve the problem.
      Build with Qt 5.12.6 MinGW 32bit

      #include <QApplication>
      #include <QMediaPlayer>
      #include <QThread>
      #include <QMetaType>
      
      #include "logger.h"
      #include "routemanager.h"
      #include "mqttclient.h"
      #include "windowmanager.h"
      #include "routewindow.h"
      
      int main(int argc, char *argv[])
      {
          qRegisterMetaType<Enums::MqttCommand>("Enums::MqttCommand");
          qRegisterMetaType<Enums::RouteState>("Enums::RouteState");
      
          QApplication a(argc, argv);
      
          Logger          logger;
          RouteManager    routeManager;
          WindowManager   windowManager;
          QMediaPlayer    clickPlayer;
          QMediaPlayer    alarmPlayer;
      
          MQTTclient      *mqttClient = new MQTTclient;
          QThread         *mqttThread = new QThread;
      
          clickPlayer.setMedia(QUrl("qrc:/sounds/click.wav"));
          alarmPlayer.setMedia(QUrl("qrc:/sounds/alarm.wav"));
      
          alarmPlayer.setVolume(0);
      
          mqttClient->moveToThread(mqttThread);
          QObject::connect(mqttThread, &QThread::started, mqttClient, &MQTTclient::initClient);
          QObject::connect(mqttThread, &QThread::finished, mqttClient, &MQTTclient::deleteLater);
          QObject::connect(mqttThread, &QThread::finished, mqttThread, &QThread::deleteLater);
      
          QObject::connect(&windowManager, &WindowManager::addToLog,              &logger,       &Logger::addToLog);
          QObject::connect(&windowManager, &WindowManager::checkSound,            &alarmPlayer,  &QMediaPlayer::play);
          QObject::connect(&windowManager, &WindowManager::setVolume,             &alarmPlayer,  &QMediaPlayer::setVolume);
          QObject::connect(&windowManager, &WindowManager::click,                 &clickPlayer,  &QMediaPlayer::play);
      
          QObject::connect(&routeManager, &RouteManager::playAlarm,           &alarmPlayer,   &QMediaPlayer::play);
      
          QObject::connect(&a, &QApplication::lastWindowClosed, mqttThread, &QThread::quit);
          QObject::connect(&a, &QApplication::aboutToQuit,      mqttThread, &QThread::quit);
      
          windowManager.initWindows();
          routeManager.initRoutes();
      
          mqttThread->start();
      
          return a.exec();
      }
      
      
      1 Reply Last reply Reply Quote 0
      • A
        Andrey Vasilyev last edited by

        It seems that the problem is somehow related to the work of the Windows defender. After disabling it, the problem did not appear yet.

        1 Reply Last reply Reply Quote 0
        • A
          Andrey Vasilyev last edited by

          The problem was in the Windows firewall. I still don't understand why this was affecting the sound, but disabling the firewall did the trick.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post