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. Is it possible to play a sound and the moment it ends do something?
Qt 6.11 is out! See what's new in the release blog

Is it possible to play a sound and the moment it ends do something?

Scheduled Pinned Locked Moved General and Desktop
10 Posts 2 Posters 6.4k 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.
  • L Offline
    L Offline
    Leon
    wrote on last edited by
    #1

    I have a button and when you press it will play a sound and say hello.

    @ if(system("canberra-gtk-play -f /usr/share/Sound.ogg&"))
    cout << "Could't play ~/usr/share/Sound.ogg. Check file existence.\n";
    cout << "Hello!" << endl;@

    But the problem is that the moment that you press the button it will play the sound and say hello before the sound ends... So how is it possible to say hello the moment that the sound ends.

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vinb
      wrote on last edited by
      #2

      I dont see any signal in the "docs":http://doc.qt.nokia.com/4.7/qsound.html , so i suspect that you have to track it yourself. You can set a timer connected with a function wich checks if isfinished == true. (on windows it always returns true :( ). And if so do anything you like.

      1 Reply Last reply
      0
      • L Offline
        L Offline
        Leon
        wrote on last edited by
        #3

        How to check if isfinished == true? Can u be more precisely?
        I am using Ubuntu so no problem, i think, with the true or false.

        1 Reply Last reply
        0
        • V Offline
          V Offline
          vinb
          wrote on last edited by
          #4

          Some not tested pseudo code:
          @
          In ".h" put QSound *sound;
          void "constructor"
          {
          QTimer *t = new QTimer(this); //create timer
          sound("path to sound");
          connect(t,SIGNAL(timeout()),this,SLOT(testFinished()));
          t->start(1000); //1 second timer
          }

          void testFinished()
          {
          if (sound->isFinished) {
          cout << "Finished" << endl;
          return;
          }
          }
          @

          1 Reply Last reply
          0
          • L Offline
            L Offline
            Leon
            wrote on last edited by
            #5

            Errors on your code:
            ‘((ArbylaPlayer*)this)->ArbylaPlayer::sound’ cannot be used as a function
            ‘((ArbylaPlayer*)this)->ArbylaPlayer::sound->QSound::isFinished’ to ‘bool’

            "Here":http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qsound.html is the QSound class reference but the

            @QSound.play("mysounds/bells.wav");@

            and the

            @QSound bells("mysounds/bells.wav");
            bells.play();@

            doesn't work.. i think it is playing in the background but you have no sound.. I have include QSound in both .h and .cpp files but still no sound..

            1 Reply Last reply
            0
            • V Offline
              V Offline
              vinb
              wrote on last edited by
              #6

              As i said, it was a pseudo not tested code. It was only to gave you an idea. :)

              Please post your code.

              Note: Use the "docs":http://doc.qt.nokia.com/4.7/qsound.html provided by Qt.

              1 Reply Last reply
              0
              • L Offline
                L Offline
                Leon
                wrote on last edited by
                #7

                Here is my code in cpp file
                @
                #include "arbylaplayer.h"
                #include "ui_arbylaplayer.h"
                #include "QSound"

                ArbylaPlayer::ArbylaPlayer(QWidget *parent) :
                QMainWindow(parent),
                ui(new Ui::ArbylaPlayer)
                {
                ui->setupUi(this);
                QSound::play("/usr/share/Sound.ogg");
                }

                ArbylaPlayer::~ArbylaPlayer()
                {
                delete ui;
                }@

                No errors but u do not hear any sound.. Any ideas?

                1 Reply Last reply
                0
                • V Offline
                  V Offline
                  vinb
                  wrote on last edited by
                  #8

                  from the docs:

                  "X11
                  The Network Audio System is used if available, otherwise all operations work silently. NAS supports WAVE and AU files."

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    Leon
                    wrote on last edited by
                    #9

                    Yes and what should i do for that? At the class reference about Qt for Embedded Linux it says: A built-in mixing sound server is used, accessing /dev/dsp directly. Only the WAVE format is supported.

                    I have a .wav file but still no sound.. :/

                    1 Reply Last reply
                    0
                    • L Offline
                      L Offline
                      Leon
                      wrote on last edited by
                      #10

                      I don't think that the sound really plays.. It must be something else.. I putted

                      @if (!QSound::isAvailable()) {
                      cout << "No sound" << endl;
                      }@

                      and the outpout is "No sound"... So something is missing.. I installed from Synaptic: nas-local server, nas-bin and libaudio-dev but i think somehow i must reconfigure Qt with NAS sound support but i do not know how to do this.. Any ideas?

                      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