Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QMediaplayer randomly plays part of the audio in a loop

QMediaplayer randomly plays part of the audio in a loop

Scheduled Pinned Locked Moved Solved General and Desktop
qmediaplayeraudioglitchloop
3 Posts 1 Posters 638 Views
  • 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 Offline
    A Offline
    Andrey Vasilyev
    wrote on 6 Feb 2021, 09:03 last edited by Andrey Vasilyev 2 Jun 2021, 09:10
    #1

    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
    0
    • A Offline
      A Offline
      Andrey Vasilyev
      wrote on 7 Feb 2021, 14:14 last edited by
      #2

      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
      0
      • A Offline
        A Offline
        Andrey Vasilyev
        wrote on 13 Feb 2021, 12:49 last edited by
        #3

        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
        0

        3/3

        13 Feb 2021, 12:49

        • Login

        • Login or register to search.
        3 out of 3
        • First post
          3/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved