qt.multimedia.player: Warning: "Failed to connect: Connection refused"
-
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.