PDA

View Full Version : Problems using QSound (Works when it wants to)



Magnus9998
3rd October 2012, 13:51
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:


soundFiles.sources = snd\*.mp3
DEPLOYMENT += soundFiles

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


QSound::play("prueba.mp3");

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:


QSound::play("trololol.mp3");

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:

8276

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:


QSound snd1("trololol.mp3");
snd1.play();

But it doesn't work either :(

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

wysota
3rd October 2012, 15:07
You are not using resources here anywhere.

Magnus9998
3rd October 2012, 21:44
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?

wysota
3rd October 2012, 21:57
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.

Magnus9998
3rd October 2012, 23:08
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.

wysota
3rd October 2012, 23:10
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

Magnus9998
4th October 2012, 12:34
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:


#include <phonon/phonon>

#include <QTemporaryFile>
#include <QResource>

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
mediaObject = new Phonon::MediaObject(this);
metaInformationResolver = new Phonon::MediaObject(this);

mediaObject->setTickInterval(1000);

Phonon::createPath(mediaObject, audioOutput);
//QSound::play("prueba.wav");
}

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


void MainWindow::PlaySound(QString file)
{
mediaObject->setCurrentSource(file);
mediaObject->play();
}

And I call it from the button slots like this:


PlaySound("qrc:/snd/trololol.mp3");

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

wysota
4th October 2012, 16:52
Does it work if you use real files?

Magnus9998
4th October 2012, 21:22
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


PlaySound("C:\test.mp3");

But it doesn't work.

wysota
4th October 2012, 21:33
Does this particular sound play if you use the regular media player for your platform?

Magnus9998
4th October 2012, 22:12
Yes, it does perfectly fine.

wysota
4th October 2012, 22:22
If you debug your app using the real device, do you get any warnings on the console while trying to play the sound?

Magnus9998
4th October 2012, 22:48
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:


void MainWindow::PlaySound(QString file)
{
QMessageBox msgBox;
mediaObject->setCurrentSource(file);
mediaObject->play();
msgBox.setText(mediaObject->errorString());
msgBox.exec();

}

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:


QFileInfo myfile(file);
if(!myfile.exists()){
QMessageBox msgBox;
msgBox.setText("File does not exist.");
msgBox.exec();
}

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.

wysota
4th October 2012, 23:20
Are you sure it exists? You are using a relative path, maybe that's the problem.

Magnus9998
5th October 2012, 10:44
Well, the file exists indeed. I tried using the following:


PlaySound("/C:/test.mp3");

And the following:


PlaySound("/test.mp3");

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


PlaySound("/qrc:/snd/prueba.mp3");

and


PlaySound("/:/snd/prueba.mp3");

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


QFileInfo myfile(file);
myfile.makeAbsolute();
if(!myfile.exists()){
QMessageBox msgBox;
msgBox.setText("File does not exist.");
msgBox.exec();
msgBox.setText(myfile.filePath());
msgBox.exec();
}

And it happens that when I call it like this:


PlaySound("qrc:/snd/prueba.mp3");

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.

wysota
7th October 2012, 17:08
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.

Magnus9998
9th October 2012, 13:04
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.