QAudioProbe not working with QMediaPlayer



  • I am using a QMediaPlayer to play back an mp3 file, and I wish to set a QAudioProbe to monitor the output. However, my call to setSource() always returns false in the following:

    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow) {
        ui->setupUi(this);
        x = new QVector<double>(256);
        y = new QVector<double>(256);
        values = new int[256];
    
        player = new QMediaPlayer();
    
        player->setMedia(QUrl::fromLocalFile(
                         "C:/Users/Person1/Desktop/piano.mp3"));
        player->setVolume(50);
        audioProbe = new QAudioProbe();
    
        if (audioProbe->setSource(player)) {
           connect(audioProbe, SIGNAL(audioBufferProbed(QAudioBuffer)),
                   this, SLOT(updatePlot(QAudioBuffer)));
        }
        else {
            qDebug("source not set");
        }
    }
    

    Please note that player and audioProbe are declared as pointers to QMediaPlayer and QAudioProbe, respectively, within the definition of the MainWindow class. The output always prints "source not set", but when I call
    player->play(), the file plays perfectly. Is there something I am missing? I have read the documentation quite thoroughly, and I could not find any problems with the method I employed. I have also tried this with different mp3 files and a few wav files; they all play, but the same problem occurs when trying to set the source. Thank you for your time.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Which OS are you running Qt on ?



  • @SGaist I am currently running Qt 5.5 on a 64-bit Windows 10 machine.


  • Lifetime Qt Champion

    IIRC, the Windows media player DirectX backend doesn't implement the QMediaAudioProbeControl but the WMF backend does



  • @SGaist, how to make it work? How to switch to the required backend?
    It used to work 1 - 1.5 years ago on Windows 7 and Qt 5.2 or 5.3!





  • I see... Had to rebuild the app with 5.5 where WMF backend was present.
    And the link doesn't seem to provide any rationale for this very odd decision. Of course, I don't care what backed is used, but I do like classes like QAudioProbe actually working.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.