Results 1 to 17 of 17

Thread: Problems using QSound (Works when it wants to)

  1. #1
    Join Date
    Oct 2012
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Problems using QSound (Works when it wants to)

    I'm trying to develop a small sound board (a program with multiple buttons, that you press and emmit a sound) for Symbian S60v5 (for a Nokia X6 device). Using Qt 4.7.4 (the most up to date version, I think). I started programming yesterday so I assume this might be a silly error or something, but this doesn't seem logical to me.

    Well, first of all, I design the application, I create the "clicked" slots using "right click > go to slot > clicked()" in each button, then I create a resource file called SoundBoard.qrc.

    I create 2 refixes, one is the '/' prefix, which contains images, and the second one is /snd, which contains the sounds. Then I store 2 sounds in /snd: "prueba.mp3" and "trololol.mp3". Both of them have the same format.

    Okay, I go to the code, and I insert the following code:

    Qt Code:
    1. soundFiles.sources = snd\*.mp3
    2. DEPLOYMENT += soundFiles
    To copy to clipboard, switch view to plain text mode 

    Inside my SoundBoard.pro file. Then I go to my MainWindow.cpp, and add the following line:

    Qt Code:
    1. QSound::play("prueba.mp3");
    To copy to clipboard, switch view to plain text mode 

    Inside one of the button's click event. I test in on my X6. It works! Yeah, it sounds.

    So, I decide to move on and try with the next sound:

    Qt Code:
    1. QSound::play("trololol.mp3");
    To copy to clipboard, switch view to plain text mode 

    The problem is, when I try it, it doesn't sound. It does sound when I try the first one, but if I add more sounds, they doesn't work. Only the first one.

    I tried building my project many times and doing all short of things but... it just doesn't want to play.

    As I started yesterday, I guess there's something I should know about using resources that I don't know. According to the documentation: http://qt-project.org/doc/qt-4.8/qsound.html
    It says that it doesn't work with resources.

    Note that QSound does not support resources. This might be fixed in a future Qt version
    But if that's true, then why does it work with my first sound, which is included in my resource files, but not with the second one? Seems confusing to me. And that's why I come to you to ask for some help. This is how my resource file looks like:

    Rj1NU.jpg

    So, I have to ask you, Is it true that it doesn't work with resources? Also, if it doesn't, what's the best way to do this?

    Ah, by the way, I heard about another way to do this:

    Qt Code:
    1. QSound snd1("trololol.mp3");
    2. snd1.play();
    To copy to clipboard, switch view to plain text mode 

    But it doesn't work either

    Thank you very much for any help, it will be much appreciated!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problems using QSound (Works when it wants to)

    You are not using resources here anywhere.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2012
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: Problems using QSound (Works when it wants to)

    Do you mean, the ':/' in the path? Because I add it and the result is exactly the same, it doesn't work. And the 'working' sound, stops working. I'm not sure if you mean that I'm using an (implied) relative path or something, but if so, why does one sound work, and others doesn't?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problems using QSound (Works when it wants to)

    Quote Originally Posted by Magnus9998 View Post
    Do you mean, the ':/' in the path? Because I add it and the result is exactly the same, it doesn't work. And the 'working' sound, stops working.
    I'm not surprised, considering that the docs claim that QSound doesn't work with resources.

    I'm not sure if you mean that I'm using an (implied) relative path or something, but if so, why does one sound work, and others doesn't?
    I meant you were focusing on resources while you were not using resources.

    QSound never was reliable. I suggest you use QtMultimediaKit or Phonon (if supported on your platform) instead.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Oct 2012
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: Problems using QSound (Works when it wants to)

    So, basically, QSound is broken/bugged or not fully developed, and that's why my program is not working correctly. Okay, I will give other classes a try. Thanks for the advise.

    As I pointed in my first post, I was already aware of QSound having issuses with resources, and since my program did work with one sound (and most results on google were pointing that QSound works with them), I though that they were fixed or something, and it was a problem related with my program. That's why I was asking.

    Also, I heard that Phonon was "overkill" for playing small sounds, and that's why I wanted to make it with QSound.

    Anyway, as I said, thanks for the advise. I will try with Phonon anyways. Hopefully, it will do the trick without wasting too much resources.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problems using QSound (Works when it wants to)

    Quote Originally Posted by Magnus9998 View Post
    Anyway, as I said, thanks for the advise. I will try with Phonon anyways. Hopefully, it will do the trick without wasting too much resources.
    I would go for QtMultimediaKit if Symbian supports it.

    http://doc.qt.digia.com/qtmobility-1.2/multimedia.html
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Oct 2012
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: Problems using QSound (Works when it wants to)

    Nope, this is impossible.

    I'm trying with Phonom but, it doesn't work either. Looks like whatever I try to do, it doesn't load resources.

    First, it did exactly the same thing. I loaded the trololol.mp3 file inside my qrc. I tried it with phonom, it worked. Now I added another sound. It doesn't work.

    So now I was trying with ':/snd/' and 'qrc:/snd/' in the path. It doesn't work either. I think I tried everything possible, I ensured that the .qrc file was in my .pro file... It doesn't load resources or doesn't want to for whatever reason. Also, the files on my project folder has the same hierachy than the .qrc file. The root folder where I have all the project files and the images, and a snd folder with the sounds inside.

    About phonom, I added the following code in my mainform.cpp:

    Qt Code:
    1. #include <phonon/phonon>
    2.  
    3. #include <QTemporaryFile>
    4. #include <QResource>
    5.  
    6. MainWindow::MainWindow(QWidget *parent)
    7. : QMainWindow(parent), ui(new Ui::MainWindow)
    8. {
    9. ui->setupUi(this);
    10. audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
    11. mediaObject = new Phonon::MediaObject(this);
    12. metaInformationResolver = new Phonon::MediaObject(this);
    13.  
    14. mediaObject->setTickInterval(1000);
    15.  
    16. Phonon::createPath(mediaObject, audioOutput);
    17. //QSound::play("prueba.wav");
    18. }
    To copy to clipboard, switch view to plain text mode 

    Then added a new method (also correctly added into the header):

    Qt Code:
    1. void MainWindow::PlaySound(QString file)
    2. {
    3. mediaObject->setCurrentSource(file);
    4. mediaObject->play();
    5. }
    To copy to clipboard, switch view to plain text mode 

    And I call it from the button slots like this:

    Qt Code:
    1. PlaySound("qrc:/snd/trololol.mp3");
    To copy to clipboard, switch view to plain text mode 

    I'm sorry, but I don't know what's wrong with my resource files

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problems using QSound (Works when it wants to)

    Does it work if you use real files?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Oct 2012
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: Problems using QSound (Works when it wants to)

    Hmmm, that's a very good question.

    I tried puting a 'test.mp3' file inside my phone internal memory (the C: drive). Then I tried

    Qt Code:
    1. PlaySound("C:\test.mp3");
    To copy to clipboard, switch view to plain text mode 

    But it doesn't work.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problems using QSound (Works when it wants to)

    Does this particular sound play if you use the regular media player for your platform?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Oct 2012
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: Problems using QSound (Works when it wants to)

    Yes, it does perfectly fine.

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problems using QSound (Works when it wants to)

    If you debug your app using the real device, do you get any warnings on the console while trying to play the sound?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #13
    Join Date
    Oct 2012
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: Problems using QSound (Works when it wants to)

    This is what I get from the console:

    Executable file: 446118 2012-10-04T23:34:57 E:\QtSDK\Symbian\SDKs\Symbian1Qt473\\epoc32\releas e\gcce\udeb\SoundBoard.exe
    Connecting to 'COM3'...
    Connected.
    Launching: SoundBoard.exe
    Launched.
    Process has finished.
    Finished.
    Finished.

    Launching debugger...
    Debugging starts
    limiting remote suggested packet size (131072 bytes) to 16384
    Debugging has finished
    And this pastebin contains the whole log from the debugger: http://pastebin.com/A8TazyjK

    I also added a few lines in my PlaySound function:

    Qt Code:
    1. void MainWindow::PlaySound(QString file)
    2. {
    3. QMessageBox msgBox;
    4. mediaObject->setCurrentSource(file);
    5. mediaObject->play();
    6. msgBox.setText(mediaObject->errorString());
    7. msgBox.exec();
    8.  
    9. }
    To copy to clipboard, switch view to plain text mode 

    It's supposed to show any error in a messagebox. It happens that the messagebox is always empty, I assume it has no errors. Also, I tried this:

    Qt Code:
    1. QFileInfo myfile(file);
    2. if(!myfile.exists()){
    3. QMessageBox msgBox;
    4. msgBox.setText("File does not exist.");
    5. msgBox.exec();
    6. }
    To copy to clipboard, switch view to plain text mode 

    Inside the same function, to make sure it exists. The program seems unable to find any files, it always give me the "File does not exist" error.

  14. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problems using QSound (Works when it wants to)

    Are you sure it exists? You are using a relative path, maybe that's the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. #15
    Join Date
    Oct 2012
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: Problems using QSound (Works when it wants to)

    Well, the file exists indeed. I tried using the following:

    Qt Code:
    1. PlaySound("/C:/test.mp3");
    To copy to clipboard, switch view to plain text mode 

    And the following:

    Qt Code:
    1. PlaySound("/test.mp3");
    To copy to clipboard, switch view to plain text mode 

    Without any success. Then I tried doing the same with the resource file

    Qt Code:
    1. PlaySound("/qrc:/snd/prueba.mp3");
    To copy to clipboard, switch view to plain text mode 

    and

    Qt Code:
    1. PlaySound("/:/snd/prueba.mp3");
    To copy to clipboard, switch view to plain text mode 

    With the same result. I also made a small modification to my playsound function:

    Qt Code:
    1. QFileInfo myfile(file);
    2. myfile.makeAbsolute();
    3. if(!myfile.exists()){
    4. QMessageBox msgBox;
    5. msgBox.setText("File does not exist.");
    6. msgBox.exec();
    7. msgBox.setText(myfile.filePath());
    8. msgBox.exec();
    9. }
    To copy to clipboard, switch view to plain text mode 

    And it happens that when I call it like this:

    Qt Code:
    1. PlaySound("qrc:/snd/prueba.mp3");
    To copy to clipboard, switch view to plain text mode 

    The filepath returns something like 'C:/Private/e0d9aabc/qrc:/snd/prueba.mp3'. However, the folder 'Private' does not exist in that directory. If I put any other path, it returns the same path I just wrote regardless of how I write it.

  16. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problems using QSound (Works when it wants to)

    Quote Originally Posted by Magnus9998 View Post
    Well, the file exists indeed.
    Neither of your attempts will verify that. You are checking paths, not the file itself. Is it physically there on the device?

    The filepath returns something like 'C:/Private/e0d9aabc/qrc:/snd/prueba.mp3'. However, the folder 'Private' does not exist in that directory.
    Or you just can't see it. I'd guess the part up to "/qrc:" is the path to your application binary. I don't know how your platform behaves but maybe it executes all apps from the C:\Private area or something like that.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  17. #17
    Join Date
    Oct 2012
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Default Re: Problems using QSound (Works when it wants to)

    It might be a problem with phonom. I tried to do the same in a Windows widget project, but the result is the same. No sound. Not even if I put the relative and absolute path to the file. But I tried opening a text file and showing it inside a text edit control, and it worked. So, the problem must be in phonon. Not in phonon itself, but in the way I'm using it.

    Edit: Never mind. I managed to get phonon working on my windows widget project, I just remade the source file from scratch and added sounds in the root of the resource file, and it worked. But I tried doing exactly the same thing on my mobile project.

    It didn't work.

    Which lead me to think that the problem is not Phonom, not QSound, and not in my program. It must be my mobile phone device.
    Last edited by Magnus9998; 9th October 2012 at 13:24.

Similar Threads

  1. Replies: 3
    Last Post: 6th July 2011, 06:59
  2. QSound on Mac
    By loveablepocky in forum Newbie
    Replies: 0
    Last Post: 16th February 2011, 01:29
  3. QSound problem?
    By anafor2004 in forum Qt Programming
    Replies: 3
    Last Post: 19th November 2008, 04:09
  4. QSound.
    By csvivek in forum Qt Programming
    Replies: 2
    Last Post: 23rd June 2008, 22:02
  5. Is QSound all there is?
    By ad5xj in forum Newbie
    Replies: 4
    Last Post: 1st September 2007, 01:31

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.