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. QMediaPlayer
Forum Updated to NodeBB v4.3 + New Features

QMediaPlayer

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 394 Views 2 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.
  • M Offline
    M Offline
    Malaluigi
    wrote on last edited by
    #1

    Dear QTDevs,
    I am struggeling with the QMediaPlayer. I can play songs and stop them. But the song has 40s and I want to use it as a notification sound. So i should only play for 8 sec and then stops. I tried some things with sleep() or delay. But it is not working and i thought there would be a way to do it more neat.

    Thanks a lot,
    Me

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

      Hi,

      For that kind of usage QSound should be used. Take a look at the audio file type constraints.

      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
      • M Offline
        M Offline
        Malaluigi
        wrote on last edited by
        #3

        What command is it there cant find anything
        Thx

        mrjjM 1 Reply Last reply
        0
        • M Malaluigi

          What command is it there cant find anything
          Thx

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

          @Malaluigi

          Hi
          There is no PlayPart or similar. You will have to call stop on it when you want it to stop before its
          actual duration.

          Some way could be.
          Note the use of static. if you only need this in one Form
          i would make QSound s a member and the function a member also.
          However, this is contained in a function using a lambda for compactness.

          void PlayNoti(int duration = 8000) /*msec*/
          {
              static QSound s("mysounds/bells.wav");
              s.play();
              QTimer::singleShot(duration, []() {
                  s.stop();
              });
          }
          
          
          1 Reply Last reply
          1
          • M Offline
            M Offline
            Malaluigi
            wrote on last edited by
            #5

            thanks mate !!!!
            LGTM

            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