【问题标题】:Qt's QMediaPlayer can't play mp3Qt的QMediaPlayer不能播放mp3
【发布时间】:2014-12-01 00:46:58
【问题描述】:

我正在使用 Qt 5.3.2 的 QMediaPlayer 在 OSX 10.10 下播放 MP3 文件,直到现在我还不能播放任何东西。

我使用的代码大致是这样的:

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

使用此功能时,我在“应用程序输出”面板中收到此错误:

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

同样的代码可以在 Windows 8 上完美运行。

谁能帮忙?

【问题讨论】:

  • 也许errorString() 也会说些有用的话。
  • errorString() 在 play() 之后显示为空;
  • 它是否适用于 OS X 10.9?
  • 无法测试,抱歉,我所有的电脑都在使用 10.10 :'(
  • 您是否安装了正确的编解码器来播放 mp3?

标签: macos qt qmediaplayer


【解决方案1】:

不久前找到了答案,将其发布在此处以供将来参考。

这个想法是 Qt 不能从资源中播放 mp3 文件。需要先将文件复制到临时文件夹。这是一种将文件从资源文件“mp3”文件夹加载到临时文件的方法:

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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多