Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to play sound with Qt

Tags:

qt

audio

How can I play sound with Qt? I tried this:

QSound::play("sounds/croack.wav");

QSound doesn't work on my ubuntu (seems that it requires NAS, although after I installed it it still doesn't work). Is there a simple one line Qt-only solution or do I need to throw in SDL or something else?

like image 657
Giovanni Funchal Avatar asked Dec 17 '10 18:12

Giovanni Funchal


1 Answers

You can use QMediaPlayer for both files format .mp3 and .wav

#include <QtMultimedia/QMediaPlayer>

QMediaPlayer *player = new QMediaPlayer;
player->setMedia(QUrl::fromLocalFile("/path"));
player->setVolume(50);
player->play();
like image 179
Am.sheikhjafari Avatar answered Oct 23 '22 05:10

Am.sheikhjafari