0

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.

Alexey Pichukov
  • 3,377
  • 2
  • 19
  • 22
cjweeks
  • 267
  • 1
  • 4
  • 8
  • did you ever solve this? I am having the same issue. See: http://stackoverflow.com/questions/34096322/generating-a-waveform-from-an-audio-or-video-file – spring Dec 05 '15 at 17:38
  • I asked this question on the Qt forum, and the reply was that the Windows media player DirectX backend doesn't implement the QMediaAudioProbeControl; however the WMF backend does, and it therefore should work. I hope this helps. – cjweeks Dec 06 '15 at 19:02

0 Answers0