Unsolved Audio playing just 1 time in qml
-
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: 6Take 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 -
The above code is perfectly working here on my machine/Qt 5.8.0.
Change loops property/ audio source and try your luck. -
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(); }