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. -
Hi and welcome to devnet,
Which OS are you running Qt on ?
-
IIRC, the Windows media player DirectX backend doesn't implement the QMediaAudioProbeControl but the WMF backend does
-
Please refer to the following article:
http://lists.qt-project.org/pipermail/interest/2016-March/021221.html
-
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 likeQAudioProbe
actually working.