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

MediaPlayer doesn't work as expected

Scheduled Pinned Locked Moved Solved QML and Qt Quick
9 Posts 2 Posters 1.6k Views
  • 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.
  • tomyT Offline
    tomyT Offline
    tomy
    wrote on 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"

    KroMignonK 1 Reply Last reply
    0
    • tomyT tomy

      @KroMignon

      I get this error:

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

      tomyT Offline
      tomyT Offline
      tomy
      wrote on 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
      • tomyT tomy

        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"

        KroMignonK Offline
        KroMignonK Offline
        KroMignon
        wrote on 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)

        tomyT 1 Reply Last reply
        0
        • KroMignonK KroMignon

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

          QT += multimedia 
          
          tomyT Offline
          tomyT Offline
          tomy
          wrote on 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.

          KroMignonK 1 Reply Last reply
          0
          • tomyT tomy

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

            KroMignonK Offline
            KroMignonK Offline
            KroMignon
            wrote on 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)

            tomyT 1 Reply Last reply
            0
            • KroMignonK KroMignon

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

              tomyT Offline
              tomyT Offline
              tomy
              wrote on last edited by
              #5

              @KroMignon

              I'm testing this program on Windows 10 x64.

              KroMignonK 2 Replies Last reply
              0
              • tomyT tomy

                @KroMignon

                I'm testing this program on Windows 10 x64.

                KroMignonK Offline
                KroMignonK Offline
                KroMignon
                wrote on 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
                • tomyT tomy

                  @KroMignon

                  I'm testing this program on Windows 10 x64.

                  KroMignonK Offline
                  KroMignonK Offline
                  KroMignon
                  wrote on 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)

                  tomyT 1 Reply Last reply
                  0
                  • KroMignonK KroMignon

                    @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)
                        }
                    }
                    
                    tomyT Offline
                    tomyT Offline
                    tomy
                    wrote on last edited by
                    #8

                    @KroMignon

                    I get this error:

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

                    tomyT 1 Reply Last reply
                    0
                    • tomyT tomy

                      @KroMignon

                      I get this error:

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

                      tomyT Offline
                      tomyT Offline
                      tomy
                      wrote on 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

                      • Login

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