Forums

OverviewV-Play 2 Support (Qt 5)BackgroundMusic not obeying settings.musicEnabled on first launch › Reply To: BackgroundMusic not obeying settings.musicEnabled on first launch

OverviewV-Play 2 Support (Qt 5)BackgroundMusic not obeying settings.musicEnabled on first launch › Reply To: BackgroundMusic not obeying settings.musicEnabled on first launch
#9847

Prashant

Hi guys,

I followed your suggestion, but the background music is not played even if I call .play(). The object thinks the settings.musicEnabled property is always false. Below is my code:

    BackgroundMusic {
        id: musicPlayer
        source: "../assets/music/razorback.mp3" // default music
        autoPlay: false
        Component.onCompleted: {
            console.log("settings.musicEnabled = " + settings.getValue("musicEnabled"))
            if (settings.musicEnabled) musicPlayer.play()
        }
    }

 

That produces the following debug output:

 

qml: settings.musicEnabled = true
qml: BackgroundMusic: did not play sound because it is disabled in GameWindow.settings

 

So to me it looks like the musicEnabled property is not properly read in the beginning.

Also, if I set autoPlay: true, I get this, but the <b>music still plays anyway</b>.

qml: BackgroundMusic: the BackgroundMusic was intended to autoPlay, but settings.musicEnabled is false (so the user did set the musicEnabled settings property in a previous app launch) ... thus do not play this music source: file:///Users/pvaibhav/Library/Developer/CoreSimulator/Devices/E5FDFA3B-4766-435F-8D8B-94CB085F0A20/data/Containers/Bundle/Application/47DA95F6-2F1B-415F-A3C1-C553E95BE530/vplay-red.app/qml/doNotPlayMusicHereOkay

 

How can we solve this?

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support