1 Attachment(s)
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:
Code:
soundFiles.sources = snd\*.mp3
DEPLOYMENT += soundFiles
Inside my SoundBoard.pro file. Then I go to my MainWindow.cpp, and add the following line:
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:
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.
Quote:
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:
Attachment 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:
But it doesn't work either :(
Thank you very much for any help, it will be much appreciated!
Re: Problems using QSound (Works when it wants to)
You are not using resources here anywhere.
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?
Re: Problems using QSound (Works when it wants to)
Quote:
Originally Posted by
Magnus9998
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.
Quote:
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.
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.
Re: Problems using QSound (Works when it wants to)
Quote:
Originally Posted by
Magnus9998
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
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:
Code:
#include <phonon/phonon>
#include <QTemporaryFile>
#include <QResource>
MainWindow
::MainWindow(QWidget *parent
){
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):
Code:
void MainWindow
::PlaySound(QString file) {
mediaObject->setCurrentSource(file);
mediaObject->play();
}
And I call it from the button slots like this:
Code:
PlaySound("qrc:/snd/trololol.mp3");
I'm sorry, but I don't know what's wrong with my resource files :(
Re: Problems using QSound (Works when it wants to)
Does it work if you use real files?
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
Code:
PlaySound("C:\test.mp3");
But it doesn't work.
Re: Problems using QSound (Works when it wants to)
Does this particular sound play if you use the regular media player for your platform?
Re: Problems using QSound (Works when it wants to)
Yes, it does perfectly fine.
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?
Re: Problems using QSound (Works when it wants to)
This is what I get from the console:
Quote:
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:
Code:
void MainWindow
::PlaySound(QString file) {
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:
Code:
if(!myfile.exists()){
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.
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.
Re: Problems using QSound (Works when it wants to)
Well, the file exists indeed. I tried using the following:
Code:
PlaySound("/C:/test.mp3");
And the following:
Code:
PlaySound("/test.mp3");
Without any success. Then I tried doing the same with the resource file
Code:
PlaySound("/qrc:/snd/prueba.mp3");
and
Code:
PlaySound("/:/snd/prueba.mp3");
With the same result. I also made a small modification to my playsound function:
Code:
myfile.makeAbsolute();
if(!myfile.exists()){
msgBox.setText("File does not exist.");
msgBox.exec();
msgBox.setText(myfile.filePath());
msgBox.exec();
}
And it happens that when I call it like this:
Code:
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.
Re: Problems using QSound (Works when it wants to)
Quote:
Originally Posted by
Magnus9998
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?
Quote:
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.
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.