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

Forums

OverviewFelgo 1 Support › Play Sound during BackgroundMusic

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

    Felgo User

    I have a BackgroundMusic playing all the time (loop), and if i collect a star i want to play a Sound (starSound.play()). but the Sound will not work.

    If i mute the BackgroundMusic, the Sound works?

    Is it possible to play a Sound during BackgroundMusic?

    Sound:

        Sound {
            id: starSound
            source: "../snd/pling.wav"
        }

    BackgroundMusic:

        // use BackgroundMusic for long-playing background sounds
        BackgroundMusic {
            id: backgroundMusic
            source: system.isPlatform(System.Meego) || system.isPlatform(System.Symbian) ? "snd/bg-slow-mono.ogg" : "snd/bg-slow.wav"
            muted: settings.soundEnabled
        }

     

     

    #6494

    Alex
    Felgo Team

    Hi,

    of course it is possibly.

    You can test it with this short project, all you need is to add your own sounds/music files:

    GameWindow {
      Scene {
        BackgroundMusic {
          source: "snd/backgroundMusic.mp3"
        }
    
        Sound {
          id:sound
          source: "snd/squafurScream.wav"
        }
    
        Column {
          anchors.centerIn: parent
          SimpleButton {
            text: "Play sound"
            onClicked:  {
              sound.play()
            }
          }
          SimpleButton {
            text: settings.soundEnabled ? "disable Sound" : "enable Sound"
            onClicked:  {
              settings.soundEnabled = !settings.soundEnabled
            }
          }
          SimpleButton {
            text: settings.musicEnabled ? "disable Music" : "enable Music"
            onClicked:  {
              settings.musicEnabled = !settings.musicEnabled
            }
          }
        }
      }
    }

    Cheers,
    Alex

    #6496

    Michael

    On a related topic, is it possible to reduce the volume of a background audio using PropertyAnimation (e.g. below)? I tried it but it seems to not work.

        BackgroundMusic {
            id: backgroundSound
            source: "snd/backgroundMusic.mp3"
            volume: 1
        }
    
        PropertyAnimation { id: myAnim; target: backgroundSound; easing.type: Easing.Linear; property: "volume"; from: "1"; to: "0"; duration: 2000}
    
        Component.onCompleted: {
            myAnim.start()
        }

     

    I’d like to try this to control the volume in certain areas of the game.

    Cheers,

    Michael.

    #6509

    Alex
    Felgo Team

    Hi Michael,

    thanks for pointing this out, we just tested on Mac OS X, iOS and Android where your code sample is working, however found a bug on Windows, is it possible that you’re also testing on a Windows PC?

    Thanks,

    Alex

     

    ps: If you want to fade the music back in again you can also use a Behavior on volume like this one:

    GameWindow {
      Scene {
        BackgroundMusic {
          id: backgroundSound
          source: "backgroundMusic.mp3"
    
          Behavior on volume { PropertyAnimation { duration: 2000 } }
        }
    
        Component.onCompleted: {
          backgroundSound.volume = 0
          // or backgroundSound.volume = 1
        }
      }
    }

     

    #6510

    Michael

    Hi Alex

    Thanks alot for your reply – yes I was testing on Windows (sorry I should have pointed this out). I’m glad about this working, this is really useful.

    Thanks alot for the other code tip – it’s really appreciated.

    Cheers, Michael.

     

     

    #6511

    Felgo User

    thx a lot, it works now.

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