Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. qt.multimedia.player: Warning: "Failed to connect: Connection refused"
Forum Updated to NodeBB v4.3 + New Features

qt.multimedia.player: Warning: "Failed to connect: Connection refused"

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 4 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • jsulmJ jsulm

    @CompSciDude It is not clear where exactly in your application this code snippet is executed. It is also not clear how mOutput and mPlayer are initialised. Can you provide more context?

    C Offline
    C Offline
    CompSciDude
    wrote on last edited by CompSciDude
    #3

    @jsulm It is not the exact code, but here is a very similar example:

    #include <memory>
    
    #include <QApplication>
    #include <QAudioOutput>
    #include <QFileInfo>
    #include <QMediaPlayer>
    #include <QObject>
    #include <QString>
    #include <QUrl>
    #include <QWidget>
    
    class SoundEffect : public QObject {
      Q_OBJECT
    
    public:
      SoundEffect(QObject* aParent, const QString& aSound)
      : QObject(aParent)
      , mSound(aSound) {
      }
    
      void PlaySound() {
        QFileInfo mSoundPath{mSound};
        QUrl mSoundUrl{mSoundPath.absoluteFilePath()};
        mOutput.setVolume(1.0);
        mPlayer.setAudioOutput(&mOutput);
        mPlayer.setSource(mSoundUrl);
        mPlayer.setLoops(QMediaPlayer::Infinite);
        mPlayer.play();
      }
    
    private:
      QString mSound;
      QAudioOutput mOutput;
      QMediaPlayer mPlayer;
    };
    
    int main(int aArgc, char** aArgv) {
      QApplication theApp{aArgc, aArgv);
    
      auto theWidget = std::make_unique<QWidget>(nullptr);
      theWidget->show();
      SoundEffect theEffect{theWidget.get(), "mySound.mp3"};
      theEffect.PlaySound();
      
      int exitCode{theApp.exec()};
      return exitCode;
    }
    
    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #4

      @CompSciDude The QUrl ctor does not take a local file path as argument so your QUrl is empty and nothing can be played.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      C 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        @CompSciDude The QUrl ctor does not take a local file path as argument so your QUrl is empty and nothing can be played.

        C Offline
        C Offline
        CompSciDude
        wrote on last edited by CompSciDude
        #5

        @Christian-Ehrlicher This is the output of qDebug() << "mSoundUrl: " << mSoundUrl;

        mSoundUrl:  QUrl("/home/compscidude/build-TestSound-Qt6-Debug/source/mySound.mp3")
        

        To me, that means QUrl is not empty. Please correct me if I am not understanding the output.

        The sound plays on Windows, but I get the qt.multimedia.player: Warning: "Failed to connect: Connection refused" on Linux.

        Christian EhrlicherC 1 Reply Last reply
        0
        • C CompSciDude

          @Christian-Ehrlicher This is the output of qDebug() << "mSoundUrl: " << mSoundUrl;

          mSoundUrl:  QUrl("/home/compscidude/build-TestSound-Qt6-Debug/source/mySound.mp3")
          

          To me, that means QUrl is not empty. Please correct me if I am not understanding the output.

          The sound plays on Windows, but I get the qt.multimedia.player: Warning: "Failed to connect: Connection refused" on Linux.

          Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by Christian Ehrlicher
          #6

          @CompSciDude said in qt.multimedia.player: Warning: "Failed to connect: Connection refused":

          To me, that means QUrl is not empty.

          This is not a valid url. Please follow my links and use the correct function to create a valid url from a local file...

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          C 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            @CompSciDude said in qt.multimedia.player: Warning: "Failed to connect: Connection refused":

            To me, that means QUrl is not empty.

            This is not a valid url. Please follow my links and use the correct function to create a valid url from a local file...

            C Offline
            C Offline
            CompSciDude
            wrote on last edited by CompSciDude
            #7

            @Christian-Ehrlicher Ok, I did that, but I am still getting qt.multimedia.player: Warning: "Failed to connect: Connection refused".

            Code

            #include <memory>
            
            #include <QApplication>
            #include <QAudioOutput>
            #include <QFileInfo>
            #include <QMediaPlayer>
            #include <QObject>
            #include <QString>
            #include <QUrl>
            #include <QWidget>
            
            class SoundEffect : public QObject {
              Q_OBJECT
            
            public:
              SoundEffect(QObject* aParent, const QString& aSound)
              : QObject(aParent)
              , mSound(aSound) {
              }
            
              void PlaySound() {
                QFileInfo soundPath{mSound};
                QString soundAbsPath{soundPath.absoluteFilePath()};
                qDebug() << "soundAbsPath: " << soundAbsPath;
                auto soundUrl = QUrl::fromLocalFile(soundAbsPath);
                qDebug() << "soundUrl: " << soundUrl;
                mOutput.setVolume(1.0);
                mPlayer.setAudioOutput(&mOutput);
                mPlayer.setSource(soundUrl);
                mPlayer.setLoops(QMediaPlayer::Infinite);
                mPlayer.play();
              }
            
            private:
              QString mSound;
              QAudioOutput mOutput;
              QMediaPlayer mPlayer;
            };
            
            int main(int aArgc, char** aArgv) {
              QApplication theApp{aArgc, aArgv};
            
              auto theWidget = std::make_unique<QWidget>(nullptr);
              theWidget->show();
              SoundEffect theEffect{theWidget.get(), "mySound.mp3"};
              theEffect.PlaySound();
              
              int exitCode{theApp.exec()};
              return exitCode;
            }
            

            Console output

            Gtk-Message: 10:01:16.982: Failed to load module "xapp-gtk3-module"
            Gtk-Message: 10:01:16.982: Failed to load module "unity-gtk-module"
            Gtk-Message: 10:01:17.027: Failed to load module "canberra-gtk-module"
            Gtk-Message: 10:01:17.028: Failed to load module "canberra-gtk-module"
            Qt: Session management error: None of the authentication protocols specified are supported
            soundAbsPath:  "/home/compscidude/build-TestSound-Qt6-Debug/source/mySound.mp3"
            soundUrl:  QUrl("file:///home/compscidude/build-TestSound-Qt6-Debug/source/mySound.mp3")
            [ALSOFT] (EE) Failed to set real-time priority for thread: Operation not permitted (1)
            qt.multimedia.player: Warning: "Failed to connect: Connection refused"
            qt.multimedia.player: Warning: "Failed to connect: Connection refused"
            

            I included all of the warning messages I am getting in case that helps diagnose the issue. I do not quite understand any of them.

            1 Reply Last reply
            1
            • C Offline
              C Offline
              CompSciDude
              wrote on last edited by
              #8

              Side-note: I found a documentation page discussing GStreamer packages for QtMultimedia. https://doc.qt.io/qt-6.2/videooverview.html#supported-media-formats.

              I will verify if I have the correct packages installed and then try again.

              1 Reply Last reply
              0
              • C Offline
                C Offline
                CompSciDude
                wrote on last edited by
                #9

                I verified I had the correct packages installed and it still gives me the connection refused error with no sound playing.

                1 Reply Last reply
                0
                • F Offline
                  F Offline
                  FinnTheHuman
                  wrote on last edited by FinnTheHuman
                  #10

                  I'm getting same error on similar problem
                  Function I'm using:

                  void MainWindow::on_Browse_clicked()
                  {
                      QString filePath = "file:/";
                      filePath += QFileDialog::getOpenFileName(this, tr("Select Audio File"), "", tr("MP3 Files (*.mp3)"));
                      qDebug() << filePath;
                  
                      mediaPlayer = new QMediaPlayer();
                      audioOutput = new QAudioOutput();
                  
                      mediaPlayer->setAudioOutput(audioOutput);
                      qDebug() << mediaPlayer->audioOutput();
                  
                  
                      mediaPlayer->setSource(QUrl::fromLocalFile(filePath));
                      mediaPlayer->setLoops(QMediaPlayer::Infinite);
                      audioOutput->setVolume(50);
                      ui->file_name->setText(filePath);
                  }
                  

                  and this is the error I am getting:

                  "file://home/Admin/Desktop/music.mp3"
                  [ALSOFT] (EE) Failed to set real-time priority for thread: Operation not permitted (1)
                  QAudioOutput(0x55a8c4ddaa70)
                  qt.multimedia.player: Unable to set the pipeline to the paused state.
                  qt.multimedia.player: Warning: "Failed to connect: Connection refused"
                  
                  1 Reply Last reply
                  1
                  • C Offline
                    C Offline
                    CompSciDude
                    wrote on last edited by
                    #11

                    Ok, I tried reconfiguring to build Qt from source and it says it does not have GStreamer support. That might be the issue. Please correct me if I am wrong, but I will investigate this.

                    1 Reply Last reply
                    0
                    • C Offline
                      C Offline
                      CompSciDude
                      wrote on last edited by
                      #12

                      I installed the libgstreamermm-1.0-dev package and doing that seemed to make the configure find GStreamer. I am going to rebuild the source and try running my application again to see if this will fix the issue.

                      1 Reply Last reply
                      0
                      • C Offline
                        C Offline
                        CompSciDude
                        wrote on last edited by
                        #13

                        Well, I rebuilt Qt 6.2.4 source, but it still gives me the error. I am out of ideas.

                        1 Reply Last reply
                        0
                        • C Offline
                          C Offline
                          CompSciDude
                          wrote on last edited by
                          #14

                          I figured out a workaround that resolves this problem: run the application via the command line.

                          1 Reply Last reply
                          0
                          • C CompSciDude has marked this topic as solved on
                          • C Offline
                            C Offline
                            CompSciDude
                            wrote on last edited by
                            #15

                            It is possible there is an issue with Qt Creator. I saw the error when running inside Qt Creator, but not when running from the command line.

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved