little sound tester

pull/22664/head
Adeeb Shihadeh 2021-10-22 17:47:46 -07:00
parent 38420a1bef
commit 4749815419
3 changed files with 33 additions and 0 deletions

View File

@ -3,6 +3,7 @@ moc_*
watch3
installer/installers/*
tests/playsound
replay/replay
replay/tests/test_replay
qt/text

View File

@ -45,6 +45,8 @@ asset_obj = qt_env.Object("assets", assets)
# build soundd
qt_env.Program("_soundd", "soundd.cc", LIBS=base_libs)
if GetOption('test'):
qt_env.Program("tests/playsound", "tests/playsound.cc", LIBS=base_libs)
# spinner and text window
qt_env.Program("qt/text", ["qt/text.cc"], LIBS=qt_libs)

View File

@ -0,0 +1,30 @@
#include <QApplication>
#include <QSoundEffect>
#include <QTimer>
#include <QDebug>
int main(int argc, char **argv) {
QApplication a(argc, argv);
QTimer::singleShot(0, [=]{
QSoundEffect s;
const char *vol = getenv("VOLUME");
s.setVolume(vol ? atof(vol) : 1.0);
for (int i = 1; i < argc; i++) {
QString fn = argv[i];
qDebug() << "playing" << fn;
QEventLoop loop;
s.setSource(QUrl::fromLocalFile(fn));
QEventLoop::connect(&s, &QSoundEffect::loadedChanged, &loop, &QEventLoop::quit);
loop.exec();
s.play();
QEventLoop::connect(&s, &QSoundEffect::playingChanged, &loop, &QEventLoop::quit);
loop.exec();
}
QCoreApplication::exit();
});
return a.exec();
}