Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. MediaPlayer doesn't work as expected
Forum Updated to NodeBB v4.3 + New Features

MediaPlayer doesn't work as expected

Scheduled Pinned Locked Moved Solved QML and Qt Quick
9 Posts 2 Posters 1.6k Views 1 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.
  • T Offline
    T Offline
    tomy
    wrote on 24 Apr 2019, 12:55 last edited by tomy
    #1

    This project is created on Qt 5.12.3:

    Here's the main.qml:

    import QtQuick 2.12
    import QtQuick.Window 2.12
    import QtQuick.Controls 2.5
    import QtMultimedia 5.12
    
    Window {
        id: window
        width: 800; height: 600
        visible: true
        color: "gray"
    
        Image {
            source: "qrc:/images/background.png"
            width: window.width / 1.2
            height: window.height / 1.2
            anchors.centerIn: parent
        }
    
        Component.onCompleted: startGameSound.play()
    
        MediaPlayer {
            id: startGameSound
            source: "qrc:/sounds/startGame.mp3"
            volume: 0.2
        }
    }
    

    I put the file startGame.mp3 in the sounds folder inside the project's directory and then added that on the qrc file.

    Now when run by the Desktop kit, the image background.png is shown but that audio file won't play!

    It was working very well on Qt 5.12.1, but I don't know why it doesn't using that new version of Qt.
    I get this message in the Application Output window:

    defaultServiceProvider::requestService(): no service found for - "org.qt-project.qt.mediaplayer"

    K 1 Reply Last reply 24 Apr 2019, 13:14
    0
    • T tomy
      24 Apr 2019, 14:30

      @KroMignon

      I get this error:

      qml: MediaPlayer error: The QMediaPlayer object does not have a valid service

      T Offline
      T Offline
      tomy
      wrote on 24 Apr 2019, 14:42 last edited by tomy
      #9

      @KroMignon

      One thing I found:

      Since I'm using a 64-bit version of Windows, so I changed the Desktop kit from MinGW 32-bit to MinGW 64-bit, and it worked! :)

      And that "MinGW 64-bit" is new in Qt 5.12.3 and I used to use "MinGW 32-bit" as before, so faced that strange behavior! When changing to "MinGW 64-bit" the problem is worked out!

      Apparently on a 64-bit version of the machine we need to use the 64-bit version of Qt which is newly provided.

      1 Reply Last reply
      0
      • T tomy
        24 Apr 2019, 12:55

        This project is created on Qt 5.12.3:

        Here's the main.qml:

        import QtQuick 2.12
        import QtQuick.Window 2.12
        import QtQuick.Controls 2.5
        import QtMultimedia 5.12
        
        Window {
            id: window
            width: 800; height: 600
            visible: true
            color: "gray"
        
            Image {
                source: "qrc:/images/background.png"
                width: window.width / 1.2
                height: window.height / 1.2
                anchors.centerIn: parent
            }
        
            Component.onCompleted: startGameSound.play()
        
            MediaPlayer {
                id: startGameSound
                source: "qrc:/sounds/startGame.mp3"
                volume: 0.2
            }
        }
        

        I put the file startGame.mp3 in the sounds folder inside the project's directory and then added that on the qrc file.

        Now when run by the Desktop kit, the image background.png is shown but that audio file won't play!

        It was working very well on Qt 5.12.1, but I don't know why it doesn't using that new version of Qt.
        I get this message in the Application Output window:

        defaultServiceProvider::requestService(): no service found for - "org.qt-project.qt.mediaplayer"

        K Offline
        K Offline
        KroMignon
        wrote on 24 Apr 2019, 13:14 last edited by
        #2

        @tomy It is perhaps a stupid question but: do you have add multimedia support in you pro file?

        QT += multimedia 
        

        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

        T 1 Reply Last reply 24 Apr 2019, 14:05
        0
        • K KroMignon
          24 Apr 2019, 13:14

          @tomy It is perhaps a stupid question but: do you have add multimedia support in you pro file?

          QT += multimedia 
          
          T Offline
          T Offline
          tomy
          wrote on 24 Apr 2019, 14:05 last edited by tomy
          #3

          @KroMignon
          Hi,
          I think that is not needed.
          I remember that "multimedia" was needed only on Mac and we needn't use it for Windows in Qt 5.12.1, but Qt 5.12.3 acts strangely!

          The problem whatever it is, it is related to MediPlayer.

          For example when I replace that MediPlayer part with:

          SoundEffect {
                  id: winGameSound
                  source: "qrc:/sounds/winGame.wav"
              }
          

          It works without any message.

          K 1 Reply Last reply 24 Apr 2019, 14:18
          0
          • T tomy
            24 Apr 2019, 14:05

            @KroMignon
            Hi,
            I think that is not needed.
            I remember that "multimedia" was needed only on Mac and we needn't use it for Windows in Qt 5.12.1, but Qt 5.12.3 acts strangely!

            The problem whatever it is, it is related to MediPlayer.

            For example when I replace that MediPlayer part with:

            SoundEffect {
                    id: winGameSound
                    source: "qrc:/sounds/winGame.wav"
                }
            

            It works without any message.

            K Offline
            K Offline
            KroMignon
            wrote on 24 Apr 2019, 14:18 last edited by
            #4

            @tomy what is your target platform: Linux, Windows, MacOS??

            It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

            T 1 Reply Last reply 24 Apr 2019, 14:19
            0
            • K KroMignon
              24 Apr 2019, 14:18

              @tomy what is your target platform: Linux, Windows, MacOS??

              T Offline
              T Offline
              tomy
              wrote on 24 Apr 2019, 14:19 last edited by
              #5

              @KroMignon

              I'm testing this program on Windows 10 x64.

              K 2 Replies Last reply 24 Apr 2019, 14:24
              0
              • T tomy
                24 Apr 2019, 14:19

                @KroMignon

                I'm testing this program on Windows 10 x64.

                K Offline
                K Offline
                KroMignon
                wrote on 24 Apr 2019, 14:24 last edited by
                #6

                @tomy Don't think it will change anything, but just to check it. Have you tried to set autoPlay?

                import QtQuick 2.12
                import QtQuick.Window 2.12
                import QtQuick.Controls 2.5
                import QtMultimedia 5.12
                
                Window {
                    id: window
                    width: 800; height: 600
                    visible: true
                    color: "gray"
                
                    Image {
                        source: "qrc:/images/background.png"
                        width: window.width / 1.2
                        height: window.height / 1.2
                        anchors.centerIn: parent
                    }
                
                    MediaPlayer {
                        id: startGameSound
                        source: "qrc:/sounds/startGame.mp3"
                        volume: 0.2
                        autoPlay: true
                    }
                }
                

                It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                1 Reply Last reply
                0
                • T tomy
                  24 Apr 2019, 14:19

                  @KroMignon

                  I'm testing this program on Windows 10 x64.

                  K Offline
                  K Offline
                  KroMignon
                  wrote on 24 Apr 2019, 14:28 last edited by
                  #7

                  @tomy you can also check if there is an error case.

                  import QtQuick 2.12
                  import QtQuick.Window 2.12
                  import QtQuick.Controls 2.5
                  import QtMultimedia 5.12
                  
                  Window {
                      id: window
                      width: 800; height: 600
                      visible: true
                      color: "gray"
                  
                      Image {
                          source: "qrc:/images/background.png"
                          width: window.width / 1.2
                          height: window.height / 1.2
                          anchors.centerIn: parent
                      }
                  
                      MediaPlayer {
                          id: startGameSound
                          source: "qrc:/sounds/startGame.mp3"
                          volume: 0.2
                          autoPlay: true
                          onError: console.log("MediaPlayer error: " + errorString)
                      }
                  }
                  

                  It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                  T 1 Reply Last reply 24 Apr 2019, 14:30
                  0
                  • K KroMignon
                    24 Apr 2019, 14:28

                    @tomy you can also check if there is an error case.

                    import QtQuick 2.12
                    import QtQuick.Window 2.12
                    import QtQuick.Controls 2.5
                    import QtMultimedia 5.12
                    
                    Window {
                        id: window
                        width: 800; height: 600
                        visible: true
                        color: "gray"
                    
                        Image {
                            source: "qrc:/images/background.png"
                            width: window.width / 1.2
                            height: window.height / 1.2
                            anchors.centerIn: parent
                        }
                    
                        MediaPlayer {
                            id: startGameSound
                            source: "qrc:/sounds/startGame.mp3"
                            volume: 0.2
                            autoPlay: true
                            onError: console.log("MediaPlayer error: " + errorString)
                        }
                    }
                    
                    T Offline
                    T Offline
                    tomy
                    wrote on 24 Apr 2019, 14:30 last edited by
                    #8

                    @KroMignon

                    I get this error:

                    qml: MediaPlayer error: The QMediaPlayer object does not have a valid service

                    T 1 Reply Last reply 24 Apr 2019, 14:42
                    0
                    • T tomy
                      24 Apr 2019, 14:30

                      @KroMignon

                      I get this error:

                      qml: MediaPlayer error: The QMediaPlayer object does not have a valid service

                      T Offline
                      T Offline
                      tomy
                      wrote on 24 Apr 2019, 14:42 last edited by tomy
                      #9

                      @KroMignon

                      One thing I found:

                      Since I'm using a 64-bit version of Windows, so I changed the Desktop kit from MinGW 32-bit to MinGW 64-bit, and it worked! :)

                      And that "MinGW 64-bit" is new in Qt 5.12.3 and I used to use "MinGW 32-bit" as before, so faced that strange behavior! When changing to "MinGW 64-bit" the problem is worked out!

                      Apparently on a 64-bit version of the machine we need to use the 64-bit version of Qt which is newly provided.

                      1 Reply Last reply
                      0

                      2/9

                      24 Apr 2019, 13:14

                      topic:navigator.unread, 7
                      • Login

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