-
Bug
-
Resolution: Fixed
-
P2: Important
-
None
-
6.2.0, 6.2.1
-
None
-
Linux, Debian 11, KDE
When I try to play an audio file with Qt 6.2, I can only hear a sound in 5 to 10% of all starts. I experienced the problem with a large project, but I can also reproduce it with the example from the Qt documentation:
void AudioDemo::playAudio() { qDebug("Play %s", qPrintable(m_fileName)); auto player = new QMediaPlayer; auto audioOutput = new QAudioOutput; player->setAudioOutput(audioOutput); player->setSource(QUrl::fromLocalFile(m_fileName)); audioOutput->setVolume(50); connect(player, &QMediaPlayer::mediaStatusChanged, this, [this](QMediaPlayer::MediaStatus status) { if (status == QMediaPlayer::EndOfMedia) emit finished(); }); connect(player, &QMediaPlayer::positionChanged, this, [](qint64 pos) { qDebug("position: %lld", pos); }); player->play(); }
class AudioDemo : public QObject { Q_OBJECT public: explicit AudioDemo(const QString& fileName, QObject* parent = nullptr) : QObject(parent), m_fileName(fileName) {} public slots: void playAudio(); signals: void finished(); private: QString m_fileName; };
int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); AudioDemo demo(argc > 1 ? argv[1] : "/some/path/to/file.mp3"); QObject::connect(&demo, &AudioDemo::finished, &a, QCoreApplication::quit); QTimer::singleShot(0, &demo, &AudioDemo::playAudio); return a.exec(); }
I can always see the positionChanged progress messages, but most of the time there is no sound.