no Audio in QML on iOS
Solved
Mobile and Embedded
-
I'm using Qt 5.12.4 (and Xcode 11) and have the following QML
import QtQuick 2.12 import QtQuick.Window 2.12 import QtMultimedia 5.8 Window { visible: true width: 640 height: 480 title: qsTr("Hello World") Audio { id: audio loops: Audio.Infinite onStatusChanged: console.log("status = " + status) onError: console.log("error = " + error + " " + errorString) onPlaybackStateChanged: console.log("playbackstate = " + playbackState) source: "qrc:/sounds/audio.mp3" volume: 1.0 } Component.onCompleted: audio.play() }
I have a
sounds
subdirectory at the same level as my .pro file and I have addedsounds/audio.mp3
to the qrc. This works fine on eg Linux and Mac. When running this application on an actual iPhone, I see the following loglinesQML debugging is enabled. Only use this in a safe environment. qml: status = 2 stale focus object QObject(0x0) , doing manual update qml: playbackstate = 1 qml: status = 6 qml: status = 7 qml: status = 3 qml: playbackstate = 0 qml: status = 6 qml: playbackstate = 1 qml: status = 7 ...
so it seems that the file is found and played back correctly. However, I can hear nothing at all. Other apps on my Phone do play sounds.
I've also tried using a construct like in my *.pro file as suggested here
SOUND_FILES = ./sounds/audio.mp3 ios { sound.files = $$SOUND_FILES sound.path = sounds QMAKE_BUNDLE_DATA = sound }
but by doing so, I always got
qml: error = 1 Attempting to play invalid Qt resource
(I tried /sounds/audio.mp3, sounds/audio.mp3, audio.mp3)Any ideas? A working example maybe?
-