SoundEffect in QML for iOS
Hi all,
I'm using Qt 5.12 and in the following project, I want to use a simple SoundEffect in QML to play a sound on iOS:
In the .pro file, I only added "multimedia" to the end of "QT += quick" and also the code block below at the end:
Code:
ios {
APP_Sounds.files = $$PWD/sounds/kimya.mp3
APP_Sounds.path = sounds
QMAKE_BUNDLE_DATA += APP_Sounds
}
The main.cpp file is intact, and without changes.
And, this is main.qml file:
Code:
import QtQuick 2.12
import QtQuick.Window 2.12
import QtMultimedia 5.12
Window {
visible: true
width: 640; height: 480
title: qsTr("Hello World")
Rectangle {
width: 100; height: 100
color: "green"
anchors.centerIn: parent
MouseArea {
anchors.fill: parent
onClicked: playExplosion.play()
}
}
SoundEffect {
id: playExplosion
source: "file:///Users/Me/QML/soundTest/soundTest/sounds/kimya.mp3"
}
}
But the problem is that, no sound played on iOS. :(
What part of this code is wrong, please?
Re: SoundEffect in QML for iOS
Have you checked the SoundEffect's status property?
Is it "Ready" when you call play()?
Cheers,
_
Re: SoundEffect in QML for iOS
I used this code for the onClicked: { part in main.qml:
Code:
...
onClicked: {
if (playExplosion.Ready)
playExplosion.play()
else console.log("Not ready")
}
...
It showed these errors when tested on Mac (Clang 64_bit kit):
QSoundEffect(qaudio): Error decoding source
qml: Not ready
And when I replace the .mp3 file with a .wav file, the first error vanishes but the error: "qml: Not Ready" still appears when I click the green rectangle.
How to make it ready, please?
Shouldn't I change the .pro or main.cpp file?
Re: SoundEffect in QML for iOS
"Ready" is just a value, you need to check if the "status" property contains that value
Code:
if (playExplosion.status === SoundEffect.Ready) {
} else {
console.log("SoundEffect status not Ready but " + playExplosion.status)
}
Cheers,
_
Re: SoundEffect in QML for iOS
Thanks so much. The problem is solved. Apparently iDevices (especially iPhones) play only .wav files within apps).