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 Offline
    A Offline
    ABouncyMi
    wrote on last edited by
    #1

    I am trying to make an application where there is a looping background music. I have added the bgm m4a file into the project via CMake. The code in MainWindow is below.

    ui->setupUi(this);
    screamer = new QMediaPlayer(this);
    audioOutput = new QAudioOutput(this);
    screamer->setAudioOutput(audioOutput);
    QString filePath = "bgm.m4a";
    qDebug() << QUrl::fromLocalFile(filePath).toString();
    screamer->setSource(QUrl::fromLocalFile(filePath));
    audioOutput->setVolume(40);
    screamer->play();
    qDebug() << screamer->errorString();
    

    Now I am quite sure that the bgm.m4a file was correctly named, the errorString() returns "", and all the codes are executed in the correct order, but there is no sound coming out of my speakers. What am I doing wrong here?

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

      Hi and welcome to devnet,

      You are using a relative path to your file. Is it located beside your application executable ?

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

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

        @SGaist said in Qt MediaPlayer doesn't play audio:

        Is it located beside your application executable ?

        Yes, I have also tried to use qt resource files but the sound still doesn't play

        Ronel_qtmasterR 1 Reply Last reply
        0
        • A ABouncyMi

          @SGaist said in Qt MediaPlayer doesn't play audio:

          Is it located beside your application executable ?

          Yes, I have also tried to use qt resource files but the sound still doesn't play

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

          @ABouncyMi When you remove set AudioOuptut does it play?
          Is there any message in the application output?
          You can check this as well https://evileg.com/en/post/155/

          A 1 Reply Last reply
          0
          • Ronel_qtmasterR Ronel_qtmaster

            @ABouncyMi When you remove set AudioOuptut does it play?
            Is there any message in the application output?
            You can check this as well https://evileg.com/en/post/155/

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

            @Ronel_qtmaster
            I've changed that, unfortunately it has the same output as before.

            Error 20 (this feature has not been implemented yet) in function AVolute::GetProductInfoT::<lambda_3920e95365a48b95dd51020986e9e351>::operator ()
            Error 20 (this feature has not been implemented yet) in function AVolute::GetProductInfoT::<lambda_3920e95365a48b95dd51020986e9e351>::operator ()
            Error 20 (this feature has not been implemented yet) in function AVolute::GetProductInfoT::<lambda_3920e95365a48b95dd51020986e9e351>::operator ()
            Error 20 (this feature has not been implemented yet) in function AVolute::GetProductInfoT::<lambda_3920e95365a48b95dd51020986e9e351>::operator ()
            Error 20 (this feature has not been implemented yet) in function AVolute::GetProductInfoT::<lambda_3920e95365a48b95dd51020986e9e351>::operator ()
            Error 20 (this feature has not been implemented yet) in function AVolute::GetProductInfoT::<lambda_3920e95365a48b95dd51020986e9e351>::operator ()
            Error 20 (this feature has not been implemented yet) in function AVolute::GetProductInfoT::<lambda_3920e95365a48b95dd51020986e9e351>::operator ()
            Error 20 (this feature has not been implemented yet) in function AVolute::GetProductInfoT::<lambda_3920e95365a48b95dd51020986e9e351>::operator ()
            Error 20 (this feature has not been implemented yet) in function AVolute::GetProductInfoT::<lambda_3920e95365a48b95dd51020986e9e351>::operator ()
            Error 20 (this feature has not been implemented yet) in function AVolute::GetProductInfoT::<lambda_3920e95365a48b95dd51020986e9e351>::operator ()
            Error 20 (this feature has not been implemented yet) in function AVolute::GetProductInfoT::<lambda_3920e95365a48b95dd51020986e9e351>::operator ()
            Error 20 (this feature has not been implemented yet) in function AVolute::GetProductInfoT::<lambda_3920e95365a48b95dd51020986e9e351>::operator ()
            "file::/audio/bgm.m4a"
            ""
            
            Ronel_qtmasterR 1 Reply Last reply
            0
            • A ABouncyMi

              @Ronel_qtmaster
              I've changed that, unfortunately it has the same output as before.

              Error 20 (this feature has not been implemented yet) in function AVolute::GetProductInfoT::<lambda_3920e95365a48b95dd51020986e9e351>::operator ()
              Error 20 (this feature has not been implemented yet) in function AVolute::GetProductInfoT::<lambda_3920e95365a48b95dd51020986e9e351>::operator ()
              Error 20 (this feature has not been implemented yet) in function AVolute::GetProductInfoT::<lambda_3920e95365a48b95dd51020986e9e351>::operator ()
              Error 20 (this feature has not been implemented yet) in function AVolute::GetProductInfoT::<lambda_3920e95365a48b95dd51020986e9e351>::operator ()
              Error 20 (this feature has not been implemented yet) in function AVolute::GetProductInfoT::<lambda_3920e95365a48b95dd51020986e9e351>::operator ()
              Error 20 (this feature has not been implemented yet) in function AVolute::GetProductInfoT::<lambda_3920e95365a48b95dd51020986e9e351>::operator ()
              Error 20 (this feature has not been implemented yet) in function AVolute::GetProductInfoT::<lambda_3920e95365a48b95dd51020986e9e351>::operator ()
              Error 20 (this feature has not been implemented yet) in function AVolute::GetProductInfoT::<lambda_3920e95365a48b95dd51020986e9e351>::operator ()
              Error 20 (this feature has not been implemented yet) in function AVolute::GetProductInfoT::<lambda_3920e95365a48b95dd51020986e9e351>::operator ()
              Error 20 (this feature has not been implemented yet) in function AVolute::GetProductInfoT::<lambda_3920e95365a48b95dd51020986e9e351>::operator ()
              Error 20 (this feature has not been implemented yet) in function AVolute::GetProductInfoT::<lambda_3920e95365a48b95dd51020986e9e351>::operator ()
              Error 20 (this feature has not been implemented yet) in function AVolute::GetProductInfoT::<lambda_3920e95365a48b95dd51020986e9e351>::operator ()
              "file::/audio/bgm.m4a"
              ""
              
              Ronel_qtmasterR Offline
              Ronel_qtmasterR Offline
              Ronel_qtmaster
              wrote on last edited by
              #6

              @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

              A 1 Reply Last reply
              0
              • Ronel_qtmasterR Ronel_qtmaster

                @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

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

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

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

                  @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

                  A 1 Reply Last reply
                  0
                  • Ronel_qtmasterR Ronel_qtmaster

                    @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

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

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

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

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

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

                      @ABouncyMi did you install klitecodec for audios and videos codecs?

                      A 1 Reply Last reply
                      0
                      • Ronel_qtmasterR Ronel_qtmaster

                        @ABouncyMi did you install klitecodec for audios and videos codecs?

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

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

                        JonBJ Ronel_qtmasterR 2 Replies Last reply
                        0
                        • 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

                                          • Login

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