Mp3 Linux Qt5

I'm on a linux and I want to get data out of an mp3. Hang in there because I know the first thing you're thinking is "this dope doesn't have his codecs set up". I'm pretty sure I do, mplayer plays mp3's, ffmpeg can encode and decode mp3, no problems there. I'm on linux fedora, I'm using qtcreator, qt5.6, and I've installed qt5multimedia. I have my .pro set up to include multimedia. Here's my mainWindow class followed by the error I'm getting;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "mainwindow.h"
#include <QAudioDecoder>
#include <QAudioFormat>
#include <QString>

#include <iostream>
#include <fstream>


QString inputFile;

QAudioBuffer *audioData;
QAudioDecoder *decoder;

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    inputFile = "sound.mp3";

    QAudioFormat af;
    af.setChannelCount(2);
    af.setSampleRate(44100);
    af.setSampleSize(16);
    af.setCodec("audio/x-raw");
    af.setSampleType(QAudioFormat::SignedInt);

    decoder = new QAudioDecoder(this);
    decoder->setAudioFormat(af);
    decoder->setSourceFilename(inputFile);

    connect(decoder, SIGNAL(bufferReady()), this, SLOT(readBuffer()));
    connect(decoder, SIGNAL(error(QAudioDecoder::Error)), this, SLOT(errorOutput()));
    decoder->start();

    errorOutput();

}

void MainWindow::readBuffer()
{

    this->close();
}

void MainWindow::errorOutput()
{
    std::cout << "Error:" << decoder->errorString().toStdString();
}

MainWindow::~MainWindow()
{

}

GStreamer; Unable to start decoding process
Error:Error:Could not open resource for reading.


I used fstream to check that the file could be accessed and it did fine, I'm not sure that my QAudioFormat is set up correctly since I couldn't find a good example for how to open mp3's. I tried downloading dnf's qt5-qtmultimedia-example package but they don't show up in qtcreator's examples area (nothing is showing up there)...

The QAudioFormat object is for the format that the decoder is supposed to decode into right?

Does anyone have an example of the correct setup?

[Edit]
I just tested on a .wav and .ogg and both showed the same errors. It's got to be my code. I'll keep looking.
Last edited on
OK, I tried to set up a simple QMediaPlayer, and I got a different message about GStreamer, one that I've seen other people have posted about on stack overflow. It appears to be a problem with my version of GStreamer not being supported by this version of Qt?

I'm not 100% on that, but I'll try downgrading my GStreamer to version 0.1 and make sure it's the dev package...

{EDIT: With Solution}


So I did that... It didn't work.
I read through 30 other posts where nobody got a resolution, then someone was good enough to post their solution...
Absolute paths. "/home/username/fileToPlay.mp3"


I tested that with the QMediaPlayer and it played, then with the above code and it worked (or at least the bufferReady signal was sent and my readBuffer function closed the program as my way of confirming the slot was activated...

So apparently while Qt accepts files from the current working directory, GStreamer expects to get absolute paths. I don't know if installing version 0.1 helped, but I doubt it since It did not affect the error message received before changing to absolute path...

I'm turning off my computer now. Brain is fried.
Last edited on
Topic archived. No new replies allowed.