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. Dynamic SoundEffect
Qt 6.11 is out! See what's new in the release blog

Dynamic SoundEffect

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 1.3k 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.
  • Q Offline
    Q Offline
    qmlnoob
    wrote on last edited by
    #1

    Hi,

    I have some SoundEffects defined, e.g. se1 and se2, and in a function, I'd like to dynamically call one according to conditions. So instead of doing:

    if (something) {
    se1.play();
    } else
    se2.play();
    }

    I'd like to do:

    var se = "se1";
    se.play();

    Is that possible?

    Many thanks

    mrjjM 1 Reply Last reply
    0
    • Q qmlnoob

      Hi,

      I have some SoundEffects defined, e.g. se1 and se2, and in a function, I'd like to dynamically call one according to conditions. So instead of doing:

      if (something) {
      se1.play();
      } else
      se2.play();
      }

      I'd like to do:

      var se = "se1";
      se.play();

      Is that possible?

      Many thanks

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @qmlnoob

      Hi
      You can set the source.
      http://doc.qt.io/qt-5/qml-qtmultimedia-soundeffect.html#source-prop

      and re-use the SoundEffect

      1 Reply Last reply
      1
      • Q Offline
        Q Offline
        qmlnoob
        wrote on last edited by
        #3

        Thanks mrjj,

        So I'd only need to define one SoundEffect then, and just use it for whatever audio file I needed?
        Would this make any difference to performance? If I had a SoundEffect for each audio file, would they be preloaded, and would this technique prevent that? Or should I still have a SoundEffect for each audio file to enable preloading, and then just change the source on one of them?

        Thanks again

        mrjjM 1 Reply Last reply
        0
        • Q qmlnoob

          Thanks mrjj,

          So I'd only need to define one SoundEffect then, and just use it for whatever audio file I needed?
          Would this make any difference to performance? If I had a SoundEffect for each audio file, would they be preloaded, and would this technique prevent that? Or should I still have a SoundEffect for each audio file to enable preloading, and then just change the source on one of them?

          Thanks again

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @qmlnoob
          well i think it resolves the source when assigned so no , it would not be preloaded before first time used.
          For later calls I assume the resource is cached so same speed there.

          Q 1 Reply Last reply
          0
          • mrjjM mrjj

            @qmlnoob
            well i think it resolves the source when assigned so no , it would not be preloaded before first time used.
            For later calls I assume the resource is cached so same speed there.

            Q Offline
            Q Offline
            qmlnoob
            wrote on last edited by
            #5

            @mrjj
            Thanks again for all the info!

            mrjjM 1 Reply Last reply
            0
            • Q qmlnoob

              @mrjj
              Thanks again for all the info!

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @qmlnoob
              Np.
              Just as note:
              https://qmlbook.github.io/

              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