Forums

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

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #9625

    Prashant

    Hi,

    I’m using the BackgroundMusic component to play .. well some background music in my app. I only have one instance of it. I also have a settings screen with a button that toggles settings.musicEnabled. This works fine and turns the music off or on. It also seems to save the setting and load it back on the next launch. I verified this by attaching the button state (on or off) directly to settings.musicEnabled property.

    However, on closing the app and restarting, even though settings.musicEnabled is false and the UI reflects it, the music still automatically plays.

    I have tried setting the muted: property to equal settings.musicEnabled. This has no effect.

    Another problem I have is the volume: property has no effect. I am using Qt 5.5.

    This is all on iOS 8.x

    #9741

    Prashant

    Anyone?

    #9749

    Alex
    V-Play Team

    Hi,
    we didn’t observe this issue yet, we will try to investigate it as soon as possible. In the meantime I suggest to work around it by setting autoPlay to false and to check setting.musicEnabled yourself at app start and call play() if true.

    Thank you for reporting the issue.

    Regards,
    Alex

    #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?

    #9849

    Prashant

    I solved it by setting autoplay to settings.musicEnabled (which is very counterintuitive, but it works..)

        BackgroundMusic {
            id: musicPlayer
            source: "../assets/music/razorback.mp3" // default music
            autoPlay: settings.musicEnabled
        }
    

     

    #9850

    Günther
    V-Play Team

    Hi,

    You are right. At the time the BackgroundMusic component is completed, the initialization of the GameWindow setting is not yet finished. So the music does not start.

    If you add the Component.onCompleted function to the GameWindow instead of the BackgroundMusic component it should work fine!

     

    Alternatively, you can try to set the music to autoPlay, and then use the onStarted signal to stop it right away if the music setting is disabled.

     

        BackgroundMusic {
          id: musicPlayer
          source: "../assets/music/razorback.mp3" // default music
          autoPlay: true
          onStarted: {
            if(!settings.musicEnabled)
              musicPlayer.stop()
          }
        }

     

    Also, thanks for sharing your solution to directly set the autoPlay property! 😉

     

    Cheers,

    GT

     

     

     

     

     

    • This reply was modified 3 years, 3 months ago by  GT.
    • This reply was modified 3 years, 3 months ago by  GT.
    • This reply was modified 3 years, 3 months ago by  GT.
    • This reply was modified 3 years, 3 months ago by  GT.
    • This reply was modified 3 years, 3 months ago by  GT.
Viewing 6 posts - 1 through 6 (of 6 total)

RSS feed for this thread

You must be logged in to reply to this topic.

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