PDA

View Full Version : not able to use QSound to play wave file



Ratheendrans
27th December 2011, 09:38
Dear All,

I want to play wave file in my application using Qt libraries 4.6.2.

I use the below code, i am calling QSound to play wave file placed in "/home/sky/1.wav" in button press event,however it doesn't work for me.can any one suggest the correct way to use.

The system shows that the sound facility is available.



void Widget::on_pushButton_clicked()
{

if(QSound::isAvailable ())
printf("Sound Facility is available\n");
else
printf("Sound Facility is not available\n");
QSound bells("/home/sky/1.wav");
bells.play();
//QSound::play("/home/guest/QtTest/image_viewer/1.wav");
printf("Inside push Button\n");
}

mvuori
27th December 2011, 12:48
It might be that QSound just doesn't work on your particular platform, for whatever reason.
You may need / want to check whether Phonon would:
http://developer.qt.nokia.com/doc/qt-4.8/phonon-overview.html

(I remember QSound not working in Maemo and having to use Phonon.)

mattc
27th December 2011, 19:21
Funny, I was about to write:
"You are creating the QSound on the stack, so the sound is supposed to stop when the block exits."

but I just tested it on Windows and it plays anyway (mmh, isn't the destructor supposed to call stop()?) Nonetheless, that might be the problem on your specific platform.

Also, if you are working on a mobile platform, check out the new QtMultimedia (http://doc.qt.nokia.com/qtmobility-1.2/multimedia.html) module in QtMobility.

Ratheendrans
28th December 2011, 06:03
Thanks for the response.

I tried the static call QSound::play("/home/sky/1.wav"),still I am facing the same issue,

Please note,I am using Qt on Embedded platform.

Regards,

Ratheendran

kuroi_neko
15th June 2012, 15:14
QSound on Windows is based on blocking PlaySound() interface, which is not interruptible. So a deleted QSound object will still play to the end (an internal cleanup daemon will take care of it once it has been played).
On platforms with a less convoluted implementation, the sound will be cut as soon as you delete the QSound object. So if you create a QSound instance as a local variable, you will barely hear a click before the function terminates and the destructor cuts off your sound.