Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-98100

No sound with QMediaPlayer

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2: Important P2: Important
    • None
    • 6.2.0, 6.2.1
    • Multimedia
    • None
    • Linux, Debian 11, KDE
    • Linux/X11

      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.

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            laknoll Lars Knoll
            ufleisch Urs Fleisch
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes