Qt MediaPlayer doesn't play audio
-
@Ronel_qtmaster
No, I only installed the extra Multimedia package from qt maintenance tool@ABouncyMi
As @Ronel_qtmaster said, I think you have to download/install any required codes, I don't think the Qt multimedia package supplies those, it expects to find them installed! -
@Ronel_qtmaster
No, I only installed the extra Multimedia package from qt maintenance tool -
@Ronel_qtmaster
Successfully installed k-lite codecs standard with default options, is there anything else I can do? There still isn't any sound -
@Ronel_qtmaster
Successfully installed k-lite codecs standard with default options, is there anything else I can do? There still isn't any sound@ABouncyMi is it at least playing? Try to create mediaplayer when a button is pressed for example, not in the constructor
-
@Ronel_qtmaster Unfortunately I can hear no sound from the application, the installation exited with no errors and I tried restarting.
I then tried using a pushbutton like this:
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QFileDialog> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); screamer = new QMediaPlayer(this); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButton_clicked() { QString video = QFileDialog::getOpenFileName(this); qDebug() << QUrl::fromLocalFile(video).toString(); screamer->setSource(QUrl::fromLocalFile(video)); screamer->play(); qDebug() << screamer->errorString(); }
No sound :(
This is surely the hardest problem I had experienced with qt -
@Ronel_qtmaster Unfortunately I can hear no sound from the application, the installation exited with no errors and I tried restarting.
I then tried using a pushbutton like this:
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QFileDialog> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); screamer = new QMediaPlayer(this); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButton_clicked() { QString video = QFileDialog::getOpenFileName(this); qDebug() << QUrl::fromLocalFile(video).toString(); screamer->setSource(QUrl::fromLocalFile(video)); screamer->play(); qDebug() << screamer->errorString(); }
No sound :(
This is surely the hardest problem I had experienced with qt@ABouncyMi could you try this?
void MainWindow::on_pushButton_clicked()
{
screamer = new QMediaPlayer(this);
QString video = QFileDialog::getOpenFileName(this);
qDebug() << QUrl::fromLocalFile(video).toString();
screamer->setSource(QUrl::fromLocalFile(video));
screamer->play();
qDebug() << screamer->errorString();
} -
@Ronel_qtmaster Unfortunately I can hear no sound from the application, the installation exited with no errors and I tried restarting.
I then tried using a pushbutton like this:
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QFileDialog> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); screamer = new QMediaPlayer(this); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButton_clicked() { QString video = QFileDialog::getOpenFileName(this); qDebug() << QUrl::fromLocalFile(video).toString(); screamer->setSource(QUrl::fromLocalFile(video)); screamer->play(); qDebug() << screamer->errorString(); }
No sound :(
This is surely the hardest problem I had experienced with qt@ABouncyMi remove screamer line in the constructor
-
One thing: QMediaPlayer is asynchronous so checking the error string right after calling play is useless.
Use the error signal and stateChanged.
-
One thing: QMediaPlayer is asynchronous so checking the error string right after calling play is useless.
Use the error signal and stateChanged.
@SGaist I tried using the https://doc.qt.io/qt-5/qmediaplayer.html#error-1 method, it gives out the error:
mainwindow.cpp:25:23: No matching function for call to 'of' qoverload.h:44:27: candidate template ignored: failed template argument deduction qoverload.h:32:27: candidate template ignored: could not match 'R (QMediaPlayer::Error)' against 'Error () const' qoverload.h:61:27: candidate template ignored: could not match 'R (*)(QMediaPlayer::Error)' against 'Error (QMediaPlayer::*)() const'
-
One thing: QMediaPlayer is asynchronous so checking the error string right after calling play is useless.
Use the error signal and stateChanged.
@SGaist I found that there isn't a stateChanged() function so I used this:
void MainWindow::on_pushButton_clicked() { screamer = new QMediaPlayer(this); QString video = QFileDialog::getOpenFileName(this); qDebug() << QUrl::fromLocalFile(video).toString(); screamer->setSource(QUrl::fromLocalFile(video)); screamer->play(); // connect(screamer, QOverload<QMediaPlayer::Error>::of(&QMediaPlayer::error()), // [=](QMediaPlayer::Error error){ // qDebug() << error; // }); connect(screamer, &QMediaPlayer::playbackStateChanged, this, &MainWindow::on_playbackState_changed); qDebug() << screamer->errorString(); } void MainWindow::on_playbackState_changed() { qDebug() << screamer->errorString(); }
the output still shows a blank string ""
-
@SGaist I found that there isn't a stateChanged() function so I used this:
void MainWindow::on_pushButton_clicked() { screamer = new QMediaPlayer(this); QString video = QFileDialog::getOpenFileName(this); qDebug() << QUrl::fromLocalFile(video).toString(); screamer->setSource(QUrl::fromLocalFile(video)); screamer->play(); // connect(screamer, QOverload<QMediaPlayer::Error>::of(&QMediaPlayer::error()), // [=](QMediaPlayer::Error error){ // qDebug() << error; // }); connect(screamer, &QMediaPlayer::playbackStateChanged, this, &MainWindow::on_playbackState_changed); qDebug() << screamer->errorString(); } void MainWindow::on_playbackState_changed() { qDebug() << screamer->errorString(); }
the output still shows a blank string ""
@ABouncyMi
You have two places where you callqDebug() << screamer->errorString();
(the first one possibly meaningless). We can't tell which it is hitting. Please put appropriate messages in. Only then will we know whetheron_playbackState_changed()
is even being hit. And iferrorString()
is empty that could mean no error. So please also connectQMediaPlayer::error()
signal correctly. You should also try reportingQMediaPlayer::isAudioAvailable()
. There are also further signals for various "changed" states which you might like to connect while you debug. -
@ABouncyMi
You have two places where you callqDebug() << screamer->errorString();
(the first one possibly meaningless). We can't tell which it is hitting. Please put appropriate messages in. Only then will we know whetheron_playbackState_changed()
is even being hit. And iferrorString()
is empty that could mean no error. So please also connectQMediaPlayer::error()
signal correctly. You should also try reportingQMediaPlayer::isAudioAvailable()
. There are also further signals for various "changed" states which you might like to connect while you debug. -
@JonB The screamer->errorString() in the on_playbackState_changed() returns "", and how do you connect error or report isAudioAvailable()?
@ABouncyMi said in Qt MediaPlayer doesn't play audio:
The screamer->errorString() in the on_playbackState_changed() returns "",
That implies to me that
playbackStateChanged()
is happening successfully, though you do not report the new playbackstate in the slot so we don't know what it has progressed to (nor how many times).and how do you connect error or report isAudioAvailable()?
I use Qt5 where connection was shown in https://doc.qt.io/qt-5/qmediaplayer.html#error-1. However I suspect you are Qt6 and that seems to have been changed, I think you now want signal void QMediaPlayer::errorOccurred(QMediaPlayer::Error error, const QString &errorString).
In Qt5 you report
qDebug() << screamer->isAudioAvailable()
. I think that too has changed at Qt6.Since I don't see that you have ever said which version of Qt you are using I don't know what you need.
-
@ABouncyMi said in Qt MediaPlayer doesn't play audio:
The screamer->errorString() in the on_playbackState_changed() returns "",
That implies to me that
playbackStateChanged()
is happening successfully, though you do not report the new playbackstate in the slot so we don't know what it has progressed to (nor how many times).and how do you connect error or report isAudioAvailable()?
I use Qt5 where connection was shown in https://doc.qt.io/qt-5/qmediaplayer.html#error-1. However I suspect you are Qt6 and that seems to have been changed, I think you now want signal void QMediaPlayer::errorOccurred(QMediaPlayer::Error error, const QString &errorString).
In Qt5 you report
qDebug() << screamer->isAudioAvailable()
. I think that too has changed at Qt6.Since I don't see that you have ever said which version of Qt you are using I don't know what you need.
-
@JonB Sorry that I forgot to say that, but I'm using the default qt6, would the case be better in qt5?
@ABouncyMi
I would not go for Qt5 just to deal with this. Unless it just doesn't work under Qt6, which I would not know. Try some other audio file formats to see if.m4a
is an issue.Google for
Error 20 (this feature has not been implemented yet) in function AVolute::GetProductInfo
. There are a few hits. Maybe you have to (re-) install something correctly. -
@ABouncyMi
I would not go for Qt5 just to deal with this. Unless it just doesn't work under Qt6, which I would not know. Try some other audio file formats to see if.m4a
is an issue.Google for
Error 20 (this feature has not been implemented yet) in function AVolute::GetProductInfo
. There are a few hits. Maybe you have to (re-) install something correctly.@JonB Already searched that, one says it's an issue of Alien computers, I don't have an Alien computer; another says it's an issue with msi audio drivers, I don't have an msi computer; another says it's a problem with Nahimic Service, I have that and disabled that according to it's instructions, that didn't work.
P.S. the official example in qt creator examples worked, so I'm not so sure if it's a hardware issue. -
@JonB Already searched that, one says it's an issue of Alien computers, I don't have an Alien computer; another says it's an issue with msi audio drivers, I don't have an msi computer; another says it's a problem with Nahimic Service, I have that and disabled that according to it's instructions, that didn't work.
P.S. the official example in qt creator examples worked, so I'm not so sure if it's a hardware issue.@ABouncyMi said in Qt MediaPlayer doesn't play audio:
P.S. the official example in qt creator examples worked, so I'm not so sure if it's a hardware issue.
Then compare your code and/or the file you are trying to play against what works there, and change code as necessary to find out where the difference is. Standard development technique.