I found another library that works fine:
Widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QtWidgets/QWidget>
#include <fmod.h>
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = nullptr);
~Widget();
private:
FMOD_SYSTEM *m_pSystem;
FMOD_SOUND *m_pSound;
};
#endif // WIDGET_H
Widget.cpp
#include "Widget.h"
#include <QtCore/QFile>
#include <QtCore/QDebug>
// https://forum.qt.io/topic/49342/solved-fmod-does-not-play-a-sound-from-qresource/2
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
FMOD_System_Create(&m_pSystem, FMOD_VERSION);
FMOD_System_Init(m_pSystem, 32, FMOD_INIT_NORMAL, 0);
// FMOD_System_CreateSound(m_pSystem, "Assets/spell.ogg", FMOD_DEFAULT, 0, &m_pSound);
QString soundPath(":/Assets/spell.ogg");
QFile f(soundPath);
if (!f.open(QIODevice::ReadOnly))
{
qDebug() << "Faild to open the file: " << soundPath;
return;
}
QByteArray soundData = f.readAll();
FMOD_CREATESOUNDEXINFO* exinfo = new FMOD_CREATESOUNDEXINFO();
exinfo->length = static_cast<unsigned int>(soundData.length());
exinfo->cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
FMOD_System_CreateSound(m_pSystem, soundData.data(), FMOD_OPENMEMORY, exinfo, &m_pSound);
FMOD_Sound_SetMode(m_pSound, FMOD_LOOP_OFF);
FMOD_System_PlaySound(m_pSystem, m_pSound, 0, false, 0);
}
Widget::~Widget()
{
}
main.cpp
#include "Widget.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
.pro
QT += core gui
INCLUDEPATH += "C:\Program Files (x86)\FMOD SoundSystem\FMOD Studio API Windows\api\core\inc"
LIBS += -L"C:\Program Files (x86)\FMOD SoundSystem\FMOD Studio API Windows\api\core\lib\x86"
LIBS += -lfmod
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
Widget.cpp
HEADERS += \
Widget.h
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
RESOURCES += \
Assets.qrc