qt.multimedia.player: Warning: "Failed to connect: Connection refused"
-
Hello,
I am building a desktop application on Ubuntu 22.04 using Qt 6.2.4. I use the following code to play a sound on loop forever.
QFileInfo mSoundPath{mSound}; QUrl mSoundUrl{mSoundPath.absoluteFilePath()}; mOutput.setVolume(1.0); mPlayer.setAudioOutput(&mOutput); mPlayer.setSource(mSoundUrl); mPlayer.setLoops(QMediaPlayer::Infinite); mPlayer.play();
It builds fine, but when I run it, the sound does not play. I see
qt.multimedia.player: Warning: "Failed to connect: Connection refused"
message in the console. I saw on another forum post that it may be an issue with gstreamer. I have gstreamer installed and the sound plays fine when I run it through gstreamer on the command line.Would anyone be able to help me diagnose the issue?
-
I figured out a workaround that resolves this problem: run the application via the command line.
-
@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?
-
@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; }
-
@CompSciDude The QUrl ctor does not take a local file path as argument so your QUrl is empty and nothing can be played.
-
@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 Ehrlicher Lifetime Qt Championreplied to CompSciDude on last edited by 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...
-
@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.
-
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.
-
I verified I had the correct packages installed and it still gives me the connection refused error with no sound playing.
-
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"
-
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.
-
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. -
Well, I rebuilt Qt 6.2.4 source, but it still gives me the error. I am out of ideas.
-
I figured out a workaround that resolves this problem: run the application via the command line.
-
-
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.