我正在使用 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 完美配合。
有人能帮忙吗?
最佳答案
刚才找到了答案,贴在这里以供日后引用。
这个想法是 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;
}
关于macos - Qt的QMediaPlayer无法播放mp3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26221649/