Qt MediaPlayer doesn't play audio
-
@ABouncyMi then you have a bug https://bugreports.qt.io/browse/QTBUG-79799
Did you try with Qmake?or simple qt exemple with qmake?It could be a problem with cmake
@Ronel_qtmaster said in Qt MediaPlayer doesn't play audio:
@ABouncyMi then you have a bug https://bugreports.qt.io/browse/QTBUG-79799
Did you try with Qmake?or simple qt exemple with qmake?It could be a problem with cmake
I tried Qmake, the same bug, but strangely the qt mediaplayer example in qt creator examples is working well, also I do not have an alien computer or msi sonic radar installed on my computer
-
@Ronel_qtmaster said in Qt MediaPlayer doesn't play audio:
@ABouncyMi then you have a bug https://bugreports.qt.io/browse/QTBUG-79799
Did you try with Qmake?or simple qt exemple with qmake?It could be a problem with cmake
I tried Qmake, the same bug, but strangely the qt mediaplayer example in qt creator examples is working well, also I do not have an alien computer or msi sonic radar installed on my computer
@ABouncyMi then it is an error in your code.Now try to open your file from QFileDialog.
QString video = QFileDialog::getOpenFileName(this);
Then set that string as the url of your video and remove Audio output -
@ABouncyMi then it is an error in your code.Now try to open your file from QFileDialog.
QString video = QFileDialog::getOpenFileName(this);
Then set that string as the url of your video and remove Audio output@Ronel_qtmaster said in Qt MediaPlayer doesn't play audio:
@ABouncyMi then it is an error in your code.Now try to open your file from QFileDialog.
QString video = QFileDialog::getOpenFileName(this);
Then set that string as the url of your video and remove Audio outputThanks for the code but it still doesn't play the audio. I'm beginning to think if it's a problem with windows or my audio driver.
P.S. why is it video when I am trying to play an audio? -
@Ronel_qtmaster said in Qt MediaPlayer doesn't play audio:
@ABouncyMi then it is an error in your code.Now try to open your file from QFileDialog.
QString video = QFileDialog::getOpenFileName(this);
Then set that string as the url of your video and remove Audio outputThanks for the code but it still doesn't play the audio. I'm beginning to think if it's a problem with windows or my audio driver.
P.S. why is it video when I am trying to play an audio?@ABouncyMi did you install klitecodec for audios and videos codecs?
-
@ABouncyMi did you install klitecodec for audios and videos codecs?
@Ronel_qtmaster
No, I only installed the extra Multimedia package from qt maintenance tool -
@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.