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 initialized 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.