Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Forums

OverviewFelgo 3 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
    Felgo 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
    Felgo 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 8 years, 8 months ago by  GT.
    • This reply was modified 8 years, 8 months ago by  GT.
    • This reply was modified 8 years, 8 months ago by  GT.
    • This reply was modified 8 years, 8 months ago by  GT.
    • This reply was modified 8 years, 8 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.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded