Solved QMediaPlayer not working in dll
-
QMediaPlayer statically compilled in exe - works correctly. Compilled in dll - does not work.
Qt 5.7.1, static build.
tst_play_exe.pro
QT += widgets multimedia CONFIG += c++14 TARGET = tst_play_exe SOURCES = tst_play_exe.cpp
tst_play_exe.cpp
#include <QApplication> #include <QPushButton> #include <QMediaPlayer> QMediaPlayer ply; int main(int argc, char *argv[]) { QApplication app(argc, argv); QPushButton btn("play"); btn.resize(100, 30); QObject::connect(&btn, &QPushButton::clicked, &ply, &QMediaPlayer::play); ply.setMedia(QUrl::fromLocalFile("d:/temp/19/example/example.mp3")); btn.show(); return app.exec(); }// main
It works.
tst_play_dll.pro
QT += core multimedia CONFIG += c++14 TARGET = tst_play_dll TEMPLATE = lib CONFIG += dll HEADERS += \ tst_play_dll.h \ SOURCES += \ tst_play_dll.cpp \
tst_play_dll.h
#ifndef TST_PLAY_DLL #define TST_PLAY_DLL #endif // TST_PLAY_DLL
tst_play_dll.cpp
#include <QMediaPlayer> #include "tst_play_dll.h" #define VERSION 0 #define ERR -1000 #define EXTERN_DLL_EXPORT extern "C" __declspec(dllexport) typedef long long si64; typedef const char* cstr; QMediaPlayer *ply = nullptr; /* !!! */ EXTERN_DLL_EXPORT int version(void) { return VERSION; } EXTERN_DLL_EXPORT void initial(void) { if(!ply) { ply = new QMediaPlayer; }} EXTERN_DLL_EXPORT void destroy(void) { delete ply; ply = nullptr; } EXTERN_DLL_EXPORT void open(cstr fnme) { initial(); ply->setMedia(QUrl::fromLocalFile(QString(fnme))); } EXTERN_DLL_EXPORT void play(cstr fnme) { open(fnme); ply->play(); } EXTERN_DLL_EXPORT void rest(void) { if(ply) { ply->pause(); }} EXTERN_DLL_EXPORT void cont(void) { if(ply) { ply->play(); }} EXTERN_DLL_EXPORT void stop(void) { if(ply) { ply->stop(); }} EXTERN_DLL_EXPORT si64 lgth(void) { return ply == nullptr ? ERR : ply->duration(); } EXTERN_DLL_EXPORT cstr lerr(void) { return ply == nullptr ? nullptr : qPrintable(ply->errorString()); }
This does not work (err: defaultServiceProvider::requestService(): no service found for - "org.qt-project.qt.mediaplayer").
Why? How to fix it?
-
@Zurg said in QMediaPlayer not working in dll:
This does not work (err: defaultServiceProvider::requestService(): no service found for - "org.qt-project.qt.mediaplayer").
did you also deploy the mediaservice plugins?
-
Hi,
Out of curiosity, why do you have that static QMediaPlayer object ?
-
Qt does not export plug-ins when creating dll.
tst_play_dll.pro
QTDIR = C:/Qt/5.7.1 QT += core multimedia CONFIG += c++14 TARGET = tst_play_dll TEMPLATE = lib CONFIG += dll HEADERS += \ tst_play_dll.h \ SOURCES += \ tst_play_dll.cpp \ LIBS += \ -L$$QTDIR/plugins/mediaservice \ $$QTDIR/plugins/mediaservice/libdsengine.a \ $$QTDIR/lib/libQt5Widgets.a \ -ldxva2 -levr -lmf -lmfplat -lmfuuid -ld3d9 \ -L$$QTDIR/plugins/audio \ -lstrmiids \
tst_play_dll.h
#ifndef TST_PLAY_DLL #define TST_PLAY_DLL #include <QtPlugin> Q_IMPORT_PLUGIN(DSServicePlugin) #endif // TST_PLAY_DLL
Working.
-
@SGaist
Play audio from foxpro. -
It has nothing to do with the fact that you are creating a .dll, it's because you are using a static build of Qt. In that case the plugin handling changes a bit.