3
votes

I'm using Qt 5.3.2's QMediaPlayer to play an MP3 file under OSX 10.10, until now I haven't been able to play anything.

The code I use is roughly this:

player = new QMediaPlayer;
player->setMedia(QUrl(soundName));
qDebug()<<soundName;
player->setVolume(50);
player->play();

When using this, I get this error in the "Application output" panel:

[19:32:52.144] FigByteFlumeCustomURLOpen signalled err=-12936 (kFigByteFlumeError_BadState) (no provider) at /SourceCache/CoreMedia/CoreMedia-1562.19/Prototypes/FigHTTP/FigByteFlumeCustomURL.c line 1486

The very same code works perfectly with Windows 8.

Can anyone help?

1
Maybe errorString() will say something useful too.Kosovan
errorString() is empty when displayed right after play();X99
Does it work with OS X 10.9?TheDarkKnight
Can't test, sorry, all of my computers are using 10.10 :'(X99
Have you installed the right codecs to play mp3?Nejat

1 Answers

0
votes

Found the answer a while ago, posting it right here for future reference.

The idea is that Qt can't play an mp3 file from resources. The files need to be copied to a temporary folder first. Here is a method to load files from resource file "mp3" folder to a temporary file:

bool Dialog::loadFiles() {
    bool success = true;

    //through mp3 folder of resources
    QDir rsc(":/mp3");
    QStringList files = rsc.entryList(QStringList()<<"*.mp3", QDir::Files);

    tmpPath = QDir::toNativeSeparators(QDir::tempPath());

    foreach(QString s, files) {
        QString srcPath = QString(":/mp3/%1").arg(s);
        QString destPath = QString("%1\\%2").arg(tmpPath).arg(s);
        mp3Files.insert(s, destPath);
        if (!QFile::exists(destPath))
            success &= QFile::copy(srcPath, destPath);
    }

    return success;
}