qt.multimedia.player: Warning: "Failed to connect: Connection refused"
-
wrote on 17 Aug 2023, 21:55 last edited by
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?
-
wrote on 2 Oct 2023, 23:41 last edited by
I figured out a workaround that resolves this problem: run the application via the command line.
-
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?
@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?
-
@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?
wrote on 18 Aug 2023, 12:55 last edited by CompSciDude@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.
-
@CompSciDude The QUrl ctor does not take a local file path as argument so your QUrl is empty and nothing can be played.
wrote on 18 Aug 2023, 14:27 last edited by 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-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.Lifetime Qt Championwrote on 18 Aug 2023, 14:34 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...
-
@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...
wrote on 18 Aug 2023, 15:18 last edited by CompSciDude@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.
-
wrote on 24 Aug 2023, 00:27 last edited by
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.
-
wrote on 25 Aug 2023, 00:22 last edited by
I verified I had the correct packages installed and it still gives me the connection refused error with no sound playing.
-
wrote on 25 Aug 2023, 17:27 last edited by FinnTheHuman
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"
-
wrote on 3 Sept 2023, 18:09 last edited by
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.
-
wrote on 3 Sept 2023, 19:44 last edited by
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. -
wrote on 3 Sept 2023, 23:09 last edited by
Well, I rebuilt Qt 6.2.4 source, but it still gives me the error. I am out of ideas.
-
wrote on 2 Oct 2023, 23:41 last edited by
I figured out a workaround that resolves this problem: run the application via the command line.
-
-
wrote on 10 Oct 2023, 03:52 last edited by
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.