Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Play sound during animation
Qt 6.11 is out! See what's new in the release blog

Play sound during animation

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 749 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    YB-2B
    wrote on last edited by
    #1

    Hello dear community,

    I'm trying to play a sound with sound effect, but only when an animation runs.

    My code is:

            if(animationX.running)
            {
                mySound.play()
    
            }else if (!animationX.running)
            {
                 mySound.stop()
    
            }
    

    I can get this sound running when the animation starts, but when the animation stops the sound continues to play and doesn't stop.

    Appreciate any help

    Thanks in advance

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #4

      Are we talking QtQuick ?
      If so, see the Animation type finished documentation

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        Why not connect the animation finished signal on your sound stop slot ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • Y Offline
          Y Offline
          YB-2B
          wrote on last edited by YB-2B
          #3

          Hi,

          my animation is in a behavior on X
          is the signal even emitted ?

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #4

            Are we talking QtQuick ?
            If so, see the Animation type finished documentation

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • Y Offline
              Y Offline
              YB-2B
              wrote on last edited by YB-2B
              #5

              Hello,
              yes it's QtQuick, but I could fix it by doing this:

                onRunningChanged:
                  {
                      if(animationX.running)
                       {
                          mySound.play()
                       }
                      if(!animationX.running)
                        {
                          mySound.stop()
                       }
                   }
              

              Thanks for your reply and your link

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved