Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt MediaPlayer doesn't play audio
Forum Updated to NodeBB v4.3 + New Features

Qt MediaPlayer doesn't play audio

Scheduled Pinned Locked Moved Unsolved General and Desktop
28 Posts 4 Posters 4.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A ABouncyMi

    @Ronel_qtmaster
    No, I only installed the extra Multimedia package from qt maintenance tool

    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by
    #12

    @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!

    1 Reply Last reply
    0
    • A ABouncyMi

      @Ronel_qtmaster
      No, I only installed the extra Multimedia package from qt maintenance tool

      Ronel_qtmasterR Offline
      Ronel_qtmasterR Offline
      Ronel_qtmaster
      wrote on last edited by
      #13

      @ABouncyMi https://codecguide.com/

      A 1 Reply Last reply
      0
      • Ronel_qtmasterR Ronel_qtmaster

        @ABouncyMi https://codecguide.com/

        A Offline
        A Offline
        ABouncyMi
        wrote on last edited by
        #14

        @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_qtmasterR 1 Reply Last reply
        0
        • A ABouncyMi

          @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_qtmasterR Offline
          Ronel_qtmasterR Offline
          Ronel_qtmaster
          wrote on last edited by Ronel_qtmaster
          #15

          @ABouncyMi is it at least playing? Try to create mediaplayer when a button is pressed for example, not in the constructor

          1 Reply Last reply
          0
          • A Offline
            A Offline
            ABouncyMi
            wrote on last edited by
            #16

            @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_qtmasterR 2 Replies Last reply
            0
            • A ABouncyMi

              @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_qtmasterR Offline
              Ronel_qtmasterR Offline
              Ronel_qtmaster
              wrote on last edited by
              #17

              @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();
              }

              1 Reply Last reply
              0
              • A ABouncyMi

                @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_qtmasterR Offline
                Ronel_qtmasterR Offline
                Ronel_qtmaster
                wrote on last edited by
                #18

                @ABouncyMi remove screamer line in the constructor

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #19

                  One thing: QMediaPlayer is asynchronous so checking the error string right after calling play is useless.

                  Use the error signal and stateChanged.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  A 2 Replies Last reply
                  0
                  • SGaistS SGaist

                    One thing: QMediaPlayer is asynchronous so checking the error string right after calling play is useless.

                    Use the error signal and stateChanged.

                    A Offline
                    A Offline
                    ABouncyMi
                    wrote on last edited by
                    #20

                    @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'
                    
                    1 Reply Last reply
                    0
                    • SGaistS SGaist

                      One thing: QMediaPlayer is asynchronous so checking the error string right after calling play is useless.

                      Use the error signal and stateChanged.

                      A Offline
                      A Offline
                      ABouncyMi
                      wrote on last edited by
                      #21

                      @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 ""

                      JonBJ 1 Reply Last reply
                      0
                      • A ABouncyMi

                        @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 ""

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by
                        #22

                        @ABouncyMi
                        You have two places where you call qDebug() << 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 whether on_playbackState_changed() is even being hit. And if errorString() is empty that could mean no error. So please also connect QMediaPlayer::error() signal correctly. You should also try reporting QMediaPlayer::isAudioAvailable(). There are also further signals for various "changed" states which you might like to connect while you debug.

                        A 1 Reply Last reply
                        0
                        • JonBJ JonB

                          @ABouncyMi
                          You have two places where you call qDebug() << 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 whether on_playbackState_changed() is even being hit. And if errorString() is empty that could mean no error. So please also connect QMediaPlayer::error() signal correctly. You should also try reporting QMediaPlayer::isAudioAvailable(). There are also further signals for various "changed" states which you might like to connect while you debug.

                          A Offline
                          A Offline
                          ABouncyMi
                          wrote on last edited by
                          #23

                          @JonB The screamer->errorString() in the on_playbackState_changed() returns "", and how do you connect error or report isAudioAvailable()?

                          JonBJ 1 Reply Last reply
                          0
                          • A ABouncyMi

                            @JonB The screamer->errorString() in the on_playbackState_changed() returns "", and how do you connect error or report isAudioAvailable()?

                            JonBJ Offline
                            JonBJ Offline
                            JonB
                            wrote on last edited by JonB
                            #24

                            @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.

                            A 1 Reply Last reply
                            0
                            • JonBJ JonB

                              @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.

                              A Offline
                              A Offline
                              ABouncyMi
                              wrote on last edited by
                              #25

                              @JonB Sorry that I forgot to say that, but I'm using the default qt6, would the case be better in qt5?

                              JonBJ 1 Reply Last reply
                              0
                              • A ABouncyMi

                                @JonB Sorry that I forgot to say that, but I'm using the default qt6, would the case be better in qt5?

                                JonBJ Offline
                                JonBJ Offline
                                JonB
                                wrote on last edited by
                                #26

                                @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.

                                A 1 Reply Last reply
                                0
                                • JonBJ JonB

                                  @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.

                                  A Offline
                                  A Offline
                                  ABouncyMi
                                  wrote on last edited by
                                  #27

                                  @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.

                                  JonBJ 1 Reply Last reply
                                  0
                                  • A ABouncyMi

                                    @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.

                                    JonBJ Offline
                                    JonBJ Offline
                                    JonB
                                    wrote on last edited by
                                    #28

                                    @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.

                                    1 Reply Last reply
                                    0

                                    • Login

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • Users
                                    • Groups
                                    • Search
                                    • Get Qt Extensions
                                    • Unsolved