Qt wiki will be updated on October 12th 2023 starting at 11:30 AM (EEST) and the maintenance will last around 2-3 hours. During the maintenance the site will be unavailable.
How to get sound on iOS: Difference between revisions
m (Added Category) |
(Described my approach that was the only one that worked for me. Couldn't make the above example work.) |
||
Line 2: | Line 2: | ||
== iOS Sound == | == iOS Sound == | ||
To play a sound file on IOS platform you can't store it in the qrc file but you have to put it in the bundle together with the qml files. | To play a sound file on IOS platform you can't store it in the qrc file but you have to put it in the bundle together with the qml files. | ||
Here | Here https://github.com/niqt/iosqt you can find my example that plays sound on IOS. | ||
The most important part is in the ''.pro'' file), where the qml and audio are put in the bundle: | The most important part is in the ''.pro'' file), where the qml and audio are put in the bundle: | ||
Line 30: | Line 30: | ||
} | } | ||
</code> | </code> | ||
== Alternate approach == | |||
Tested in 2020 and the above example was not working for me. Instead I made it work by these edits: | |||
1) Included all content in my audio folder where I stored the sound files. The path attribute creates a new directory for your data. I haven't used it here keeping the bundled data in root.<syntaxhighlight lang="qbasic"> | |||
ios: { | |||
BUNDLE_DATA.files = $$files($$PWD/audio/*.mp3) | |||
QMAKE_BUNDLE_DATA += BUNDLE_DATA | |||
} | |||
</syntaxhighlight>2) Used the same plugin inclusions as above. | |||
3) Had to locate the file in QML like this:<syntaxhighlight lang="qml"> | |||
source: StandardPaths.locate(StandardPaths.AppDataLocation, "file.mp3", StandardPaths.LocateFile) | |||
</syntaxhighlight>Providing the URL by Standard Paths made it possible for the Media Player to open the file. The file couldn't be found without this. |
Latest revision as of 13:47, 21 July 2020
iOS Sound
To play a sound file on IOS platform you can't store it in the qrc file but you have to put it in the bundle together with the qml files. Here https://github.com/niqt/iosqt you can find my example that plays sound on IOS. The most important part is in the .pro file), where the qml and audio are put in the bundle:
DATA_FILES = $$PWD/qml/iosqt/main.qml ../iosqt/page.qml ../iosqt/audio.mp3
ios: {
data.files = $$DATA_FILES
data.path = Documents
QMAKE_BUNDLE_DATA *= data
}
obviously you have to include the plugin:
QTPLUGIN *= qtaudio_coreaudio
QTPLUGIN *= qtmedia_audioengine
QTPLUGIN *= qavfcamera
QTPLUGIN *= qavfmediaplayer
thus in main.qml:
MediaPlayer {
id: playMusic
volume: 0.5
source: "audio.mp3"
}
Alternate approach
Tested in 2020 and the above example was not working for me. Instead I made it work by these edits:
1) Included all content in my audio folder where I stored the sound files. The path attribute creates a new directory for your data. I haven't used it here keeping the bundled data in root.
ios: {
BUNDLE_DATA.files = $$files($$PWD/audio/*.mp3)
QMAKE_BUNDLE_DATA += BUNDLE_DATA
}
2) Used the same plugin inclusions as above. 3) Had to locate the file in QML like this:
source: StandardPaths.locate(StandardPaths.AppDataLocation, "file.mp3", StandardPaths.LocateFile)
Providing the URL by Standard Paths made it possible for the Media Player to open the file. The file couldn't be found without this.