supportedMimeTypes
-
I am having trouble playing a simple sound file using QSound, in the latest Qt5.6 (though it was also problem in Qt5.5.1), Win7 32-bit and VS 2013 with Qt Add-in version 1.2.5. Here is the code in the constructor of a class with two QSound * members, m_HI and m_Lo. The highFile and lowFile definitely exist, as confirmed by QFile.exists() call. Note the call to QSoundEffect::supportMimeTypes: this always returns 0-length list! I think that may be the problem, though not at all sure!
m_Hi = new QSound(highFile.fileName(), this); m_Lo = new QSound(lowFile.fileName(), this); m_Hi->setLoops(QSound::Infinite); m_Lo->setLoops(QSound::Infinite); qDebug() << "BIPSMetronome: Period = " << m_uPeriod_ms << " Hi Note filename = " << m_Hi->fileName(); m_bStop = false; QStringList mimTyp(QSoundEffect::supportedMimeTypes()); if (mimTyp.length() > 0) { int ii; for (ii = 0; ii < mimTyp.length(); ii++) { qDebug() << mimTyp.at(ii); } } else qDebug() << "No MIME Types!!!";
Later calls to m_Hi->play() or m_Lo->play() do nothing, no sound and no error messages.
This code chunk is from a very large project. In the .pro file I have the following:QT += core gui multimedia widgets multimediawidgets DEFINES += QT_DLL QT_MULTIMEDIA_LIB QT_MULTIMEDIAWIDGETS_LIB QT_WIDGETS_LIB
In an attempt to figure this out, I created a very simple application that only reads the same .wav files. Here is the code from that project:
void TestSound::on_testSndBtn_clicked() { QStringList mimTyp(QSoundEffect::supportedMimeTypes()); QString fstMIME; if (mimTyp.length() > 0) { int ii; fstMIME = QString("MIMES %1, First = %2").arg(mimTyp.length()).arg(mimTyp.at(0)); } else { fstMIME = "No MIME Types!!!"; } if (tstSnd) delete tstSnd; tstSnd = new QSound("C:/kcbdev/bips_svn/BIPS10/BIPSWidgets/sounds/highnote8orig.wav"); tstSnd->play(); }
This code runs just fine! It reports 4 MimeTypes, and the tstSnd->play() works just fine. In the .pro file I find the following two lines:
QT += core multimedia widgets gui multimediawidgets DEFINES += WIN64 QT_DLL QT_MULTIMEDIA_LIB QT_MULTIMEDIAWIDGETS_LIB QT_WIDGETS_LIB
Sorry for the length of this, I wanted to detail what I have been through. I know I am missing something somewhere, not linking to a required library or something. If anyone can see an obvious problem, please let me know!
-
@nekkceb I downloaded the Qt5.6 source and built debug version to test things out. In my small app, with only a 'Test Sound' button, I can single-step into
QSoundEffect::supportedMimeTypes()
which leads me into
QAudioDeviceFactory::availableDevices(QAudio::Mode mode)
The code I find here is:
QList<QAudioDeviceInfo> devices; #if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS) QMediaPluginLoader* l = audioLoader(); foreach (const QString& key, l->keys()) { QAudioSystemFactoryInterface* plugin = qobject_cast<QAudioSystemFactoryInterface*>(l->instance(key)); if (plugin) { foreach (QByteArray const& handle, plugin->availableDevices(mode)) devices << QAudioDeviceInfo(key, handle, mode); } } #endif
Note the #if !defined wrapper: could this be the problem? In my larger program that does NOT work, even when I re-compile with this built-from-source debug vesrion of Qt, when I get to the line
QSoundEffect::supportedMimeTypes()
the debugger just passes over it without stepping into. It is as if this whole module is not linked! So, does anyone know how QSoundEffect can be excluded from the build? I have tested for
#if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS) ret = QMessageBox::warning(this, tr("Test Sound"), QString("QT_NO_LIBRARY NOT defined"), QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save); #endif
The message box appears, suggesting I do NOT have QT_NO_LIBRARY set, yet the larger program acts as if it is not included in the compile/link.
Any help would be appreciated.