Results 1 to 5 of 5

Thread: play sound repeatedly

  1. #1
    Join Date
    Nov 2010
    Posts
    23
    Thanks
    10
    Qt products
    Qt/Embedded
    Platforms
    MacOS X Windows

    Default play sound repeatedly

    Hi guys, i have a little problem using sound at Qt
    im creating music player with qt

    right now, i'm using phonon each time i want to play the sound, for example:

    void drumplayer:lay_snare()
    {
    snare = Phonon::CreatePlayer(Phonon::MusicCategory, Phonon::MediaSource(path));
    snare->play();
    }

    with that code, every time i play the snare of the drum, there will be new object created (and will use the memory a lot for each play).

    i have tried to make the initiation of snare separated like this:

    void drumplayer::init_snare()
    {
    snare = Phonon::CreatePlayer(Phonon::MusicCategory, Phonon::MediaSource(path));
    }
    void drumplayer:lay_snare()
    {
    snare->play();
    }

    but i cant play the snare repeatedly. If i wan't to play the snare again, i have to put snare->stop(); before i can play again. I also try QSound, but QSound can't play multiple sound

    Is there another way to play multiple sound repeatedly?
    thx a lot for your help

  2. #2
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: play sound repeatedly

    hi,
    did u try
    QSound void setLoops ( int l ) ;

    hope it helps
    Bala

  3. The following user says thank you to BalaQT for this useful post:

    ardisaz (4th December 2010)

  4. #3
    Join Date
    Mar 2008
    Location
    Houston, Texas, USA
    Posts
    277
    Thanks
    9
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: play sound repeatedly

    Have you tried MediaObject::setCurrentSource where it will change the source of the file you want to execute rather than keep creating it like you are doing which is wrong. Then just call play when you need it.
    Qt-4.7.3 | Gentoo ~amd64 | KDE-4.7
    Aki IRC Client for KDE4 | Qt Documentation

  5. The following user says thank you to ComaWhite for this useful post:

    ardisaz (4th December 2010)

  6. #4
    Join Date
    Nov 2010
    Posts
    23
    Thanks
    10
    Qt products
    Qt/Embedded
    Platforms
    MacOS X Windows

    Default Re: play sound repeatedly

    @Bala, thank for your suggestion. But QSound doesn't support multiple sound. Each time i touch another label, the other sound is off

    @comaWhite, yes i already try that. But that technique won't let my program use multiple sound.

    thx for your suggestion...

  7. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: play sound repeatedly

    what do you mean with multiple? Do you mean you want to play two ore more files at the same moment? If so, you have to construct two or more players. If you play them in a sequence see the queue functions.

Similar Threads

  1. Phonon, play sound on key press
    By ale6111 in forum Qt Programming
    Replies: 0
    Last Post: 1st August 2010, 16:18
  2. How to play a sound from a resource file?
    By Asperamanca in forum Newbie
    Replies: 3
    Last Post: 21st July 2010, 17:28
  3. Play .amr sound
    By ahmdsd_ostora in forum Qt Programming
    Replies: 3
    Last Post: 17th July 2010, 15:34
  4. Phonon Cannot Play Sound (without Error)
    By padawan in forum Qt Programming
    Replies: 5
    Last Post: 16th September 2009, 15:17
  5. MP3 Sound / OGG Sound Play on GUI
    By patrik08 in forum Newbie
    Replies: 3
    Last Post: 1st September 2006, 19:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.