Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

audio - How to play sound with Qt

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...