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. Audio playing just 1 time in qml
Qt 6.11 is out! See what's new in the release blog

Audio playing just 1 time in qml

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 1.3k 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.
  • mkrrM Offline
    mkrrM Offline
    mkrr
    wrote on last edited by
    #1

    Hi,

    I'm with a problem in my qml Audio Component.

    I'm trying to play a song with a MouseArea onClicked event.

    The problem is that the Audio play's just one time. For example: If I click on the mouse on the first time, the Audio has been executed, but if I click again the audio will not play more.

    I can see an anormal thing. The output of the function "onStatusChanged" of the Audio component is printing the sequence: 2, 3, 6, 7, 6. And never returns to 7 status. Take a look below.
    qml: status: 2
    qml: status: 3
    qml: status: 6
    qml: status: 7
    qml: status: 6

    Take a look in my source code:

    import QtQuick 2.4
    import QtQuick.Window 2.2
    import QtMultimedia 5.0
    
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        Audio {
            id: playMusic
            source: "button.wav"
            onStatusChanged: {
                console.log('status: ' + status);
            }
        }
    
        MainForm {
            anchors.fill: parent
            mouseArea.onClicked: {
                playMusic.play();
            }
        }
    }
    

    I'm using QT 5.4.3 version.

    Some idea, to help me?
    Thanks

    1 Reply Last reply
    0
    • YashpalY Offline
      YashpalY Offline
      Yashpal
      wrote on last edited by
      #2

      The above code is perfectly working here on my machine/Qt 5.8.0.
      Change loops property/ audio source and try your luck.

      1 Reply Last reply
      0
      • mkrrM Offline
        mkrrM Offline
        mkrr
        wrote on last edited by mkrr
        #3

        Yes. In another machine with Qt 5.6 it's working normal for me.

        I make a test, changing the "source" property of the Audio element. I built a function to reset the source and it's working normally. I would like to know the mistery thats happening . Take a look in my function (Its working with it):

            function soundPlay(sound) {
                var src = sound.source;
                sound.source = "";
                sound.source = src;
                sound.play();
            }
        
        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