Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QMediaPlayer not working in dll

QMediaPlayer not working in dll

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 1.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    Zurg
    wrote on last edited by Zurg
    #1

    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?

    raven-worxR 1 Reply Last reply
    0
    • Z Zurg

      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?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @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?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Out of curiosity, why do you have that static QMediaPlayer object ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        Z 1 Reply Last reply
        1
        • Z Offline
          Z Offline
          Zurg
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • SGaistS SGaist

            Hi,

            Out of curiosity, why do you have that static QMediaPlayer object ?

            Z Offline
            Z Offline
            Zurg
            wrote on last edited by
            #5

            @SGaist
            Play audio from foxpro.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved