Results 1 to 5 of 5

Thread: SoundEffect in QML for iOS

  1. #1
    Join Date
    Jan 2016
    Posts
    76
    Thanks
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows Android

    Default 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:

    Qt Code:
    1. ios {
    2. APP_Sounds.files = $$PWD/sounds/kimya.mp3
    3. APP_Sounds.path = sounds
    4. QMAKE_BUNDLE_DATA += APP_Sounds
    5. }
    To copy to clipboard, switch view to plain text mode 

    The main.cpp file is intact, and without changes.

    And, this is main.qml file:

    Qt Code:
    1. import QtQuick 2.12
    2. import QtQuick.Window 2.12
    3. import QtMultimedia 5.12
    4.  
    5. Window {
    6. visible: true
    7. width: 640; height: 480
    8. title: qsTr("Hello World")
    9.  
    10. Rectangle {
    11. width: 100; height: 100
    12. color: "green"
    13. anchors.centerIn: parent
    14.  
    15. MouseArea {
    16. anchors.fill: parent
    17. onClicked: playExplosion.play()
    18. }
    19. }
    20.  
    21. SoundEffect {
    22. id: playExplosion
    23. source: "file:///Users/Me/QML/soundTest/soundTest/sounds/kimya.mp3"
    24. }
    25. }
    To copy to clipboard, switch view to plain text mode 

    But the problem is that, no sound played on iOS.
    What part of this code is wrong, please?
    Last edited by franky; 15th April 2019 at 09:16.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: SoundEffect in QML for iOS

    Have you checked the SoundEffect's status property?

    Is it "Ready" when you call play()?

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    franky (15th April 2019)

  4. #3
    Join Date
    Jan 2016
    Posts
    76
    Thanks
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: SoundEffect in QML for iOS

    I used this code for the onClicked: { part in main.qml:

    Qt Code:
    1. ...
    2. onClicked: {
    3. if (playExplosion.Ready)
    4. playExplosion.play()
    5. else console.log("Not ready")
    6. }
    7. ...
    To copy to clipboard, switch view to plain text mode 

    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?
    Last edited by franky; 15th April 2019 at 13:51.

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: SoundEffect in QML for iOS

    "Ready" is just a value, you need to check if the "status" property contains that value

    Qt Code:
    1. if (playExplosion.status === SoundEffect.Ready) {
    2. } else {
    3. console.log("SoundEffect status not Ready but " + playExplosion.status)
    4. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  6. The following user says thank you to anda_skoa for this useful post:

    franky (15th April 2019)

  7. #5
    Join Date
    Jan 2016
    Posts
    76
    Thanks
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: SoundEffect in QML for iOS

    Thanks so much. The problem is solved. Apparently iDevices (especially iPhones) play only .wav files within apps).

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.