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. Don't play mp3
Forum Updated to NodeBB v4.3 + New Features

Don't play mp3

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 4 Posters 237 Views
  • 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.
  • M Offline
    M Offline
    Mihaill
    wrote last edited by
    #1

    Hi!
    How play audio?
    If I do this:

    QMediaPlayer m_player;
    m_player.setSource(QUrl(m_lastPath));
    QAudioOutput *audioOutput = new QAudioOutput;
    m_player.setAudioOutput(audioOutput);
    m_player.play();
    

    Then I get eoor:

    [mp3 @ 000001E640C19B00] Could not find codec parameters for stream 1 (Video: png, none): unspecified size
    Consider increasing the value for the 'analyzeduration' (0) and 'probesize' (5000000) options
    Input #0, mp3, from 'C:/Users/Admin/AppData/Local/Temp/MM terminal.GtMcrE.mp3':
      Metadata:
        artist          : Sound Clip
        title           : Военно-морской сигнал тревоги 
        encoder         : Lavf56.40.101
        date            : 2020
      Duration: 00:00:08.39, start: 0.011995, bitrate: 130 kb/s
      Stream #0:0: Audio: mp3 (mp3float), 44100 Hz, stereo, fltp, 128 kb/s
          Metadata:
            encoder         : LAME3.97 
          Side data:
            replaygain: track gain - -10.600000, track peak - unknown, album gain - unknown, album peak - unknown, 
      Stream #0:1: Video: png, none, 90k tbr, 90k tbn (attached pic)
          Metadata:
            title           : Album cover
            comment         : Cover (front)
    

    In qt5 audio player was normal work with this file.

    jsulmJ 1 Reply Last reply
    0
    • M Offline
      M Offline
      Mihaill
      wrote last edited by
      #12

      it's work with vlc

      #pragma once
      
      #include <QObject>
      #include <vlc/vlc.h>
      #include <QString>
      #include <QUrl>
      #include <QTimer>
      
      class VlcAudioPlayer : public QObject
      {
          Q_OBJECT
      public:
          explicit VlcAudioPlayer(QObject* parent = nullptr);
          ~VlcAudioPlayer();
      
          // Запустить воспроизведение аудиофайла по локальному пути
          bool play(const QString& filePath);
      
          // Остановить воспроизведение
          void stop();
      
          // Проверить, играет ли сейчас аудио
          bool isPlaying() const;
      
      signals:
          void started();
          void stopped();
          void finished();
      
      private slots:
          void checkPlayback();
      
      private:
          libvlc_instance_t* m_instance = nullptr;
          libvlc_media_player_t* m_mediaPlayer = nullptr;
          QTimer m_timer;
      };
      
      #include "VlcAudioPlayer.h"
      #include <QDebug>
      
      VlcAudioPlayer::VlcAudioPlayer(QObject* parent)
          : QObject(parent)
      {
          const char* args[] = { "--no-xlib" };
          m_instance = libvlc_new(1, args);
          if (!m_instance) {
              qWarning() << "Failed to create libVLC instance";
          }
      
          m_mediaPlayer = nullptr;
      
          // Таймер для проверки состояния воспроизведения
          connect(&m_timer, &QTimer::timeout, this, &VlcAudioPlayer::checkPlayback);
          m_timer.setInterval(200); // проверять каждые 200 мс
      }
      
      VlcAudioPlayer::~VlcAudioPlayer()
      {
          if (m_mediaPlayer) {
              libvlc_media_player_stop(m_mediaPlayer);
              libvlc_media_player_release(m_mediaPlayer);
          }
          if (m_instance) {
              libvlc_release(m_instance);
          }
      }
      
      bool VlcAudioPlayer::play(const QString& filePath)
      {
          if (!m_instance) {
              qWarning() << "libVLC instance is null";
              return false;
          }
      
          // Если уже играет, остановим
          if (isPlaying()) {
              stop();
          }
      
          // Преобразуем путь в URI
          QUrl url = QUrl::fromLocalFile(filePath);
          QString uri = url.toString();
      
          libvlc_media_t* media = libvlc_media_new_location(m_instance, uri.toUtf8().constData());
          if (!media) {
              qWarning() << "Failed to create media from URI:" << uri;
              return false;
          }
      
          if (m_mediaPlayer) {
              libvlc_media_player_stop(m_mediaPlayer);
              libvlc_media_player_release(m_mediaPlayer);
              m_mediaPlayer = nullptr;
          }
      
          m_mediaPlayer = libvlc_media_player_new_from_media(media);
          libvlc_media_release(media);
      
          if (!m_mediaPlayer) {
              qWarning() << "Failed to create media player";
              return false;
          }
      
          if (libvlc_media_player_play(m_mediaPlayer) != 0) {
              qWarning() << "Failed to start playback";
              libvlc_media_player_release(m_mediaPlayer);
              m_mediaPlayer = nullptr;
              return false;
          }
      
          emit started();
          m_timer.start();
      
          return true;
      }
      
      void VlcAudioPlayer::stop()
      {
          if (m_mediaPlayer && isPlaying()) {
              libvlc_media_player_stop(m_mediaPlayer);
              emit stopped();
          }
          m_timer.stop();
      }
      
      bool VlcAudioPlayer::isPlaying() const
      {
          if (!m_mediaPlayer)
              return false;
          return libvlc_media_player_is_playing(m_mediaPlayer) != 0;
      }
      
      void VlcAudioPlayer::checkPlayback()
      {
          if (!m_mediaPlayer) {
              m_timer.stop();
              return;
          }
      
          if (!isPlaying()) {
              m_timer.stop();
              emit finished();
          }
      }
      
      
      1 Reply Last reply
      0
      • M Mihaill

        Hi!
        How play audio?
        If I do this:

        QMediaPlayer m_player;
        m_player.setSource(QUrl(m_lastPath));
        QAudioOutput *audioOutput = new QAudioOutput;
        m_player.setAudioOutput(audioOutput);
        m_player.play();
        

        Then I get eoor:

        [mp3 @ 000001E640C19B00] Could not find codec parameters for stream 1 (Video: png, none): unspecified size
        Consider increasing the value for the 'analyzeduration' (0) and 'probesize' (5000000) options
        Input #0, mp3, from 'C:/Users/Admin/AppData/Local/Temp/MM terminal.GtMcrE.mp3':
          Metadata:
            artist          : Sound Clip
            title           : Военно-морской сигнал тревоги 
            encoder         : Lavf56.40.101
            date            : 2020
          Duration: 00:00:08.39, start: 0.011995, bitrate: 130 kb/s
          Stream #0:0: Audio: mp3 (mp3float), 44100 Hz, stereo, fltp, 128 kb/s
              Metadata:
                encoder         : LAME3.97 
              Side data:
                replaygain: track gain - -10.600000, track peak - unknown, album gain - unknown, album peak - unknown, 
          Stream #0:1: Video: png, none, 90k tbr, 90k tbn (attached pic)
              Metadata:
                title           : Album cover
                comment         : Cover (front)
        

        In qt5 audio player was normal work with this file.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote last edited by
        #2

        @Mihaill Add error handling to your code to see whether there are any errors (https://doc.qt.io/archives/qt-5.15/qmediaplayer.html#error-1)
        Also connect a slot to https://doc.qt.io/archives/qt-5.15/qmediaplayer.html#stateChanged and see which state changes you have.

        I hope m_player is not a local variable which gets destroyed when its scope is gone...

        "Then I get eoor:" - I don't see any errors related to audio playback.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        M 1 Reply Last reply
        1
        • M Offline
          M Offline
          Mihaill
          wrote last edited by Mihaill
          #3

          @jsulm
          m_player is variable in my class
          m_player dont emited signal error()
          m_player change status on QMediaPlayer::LoadingMedia
          after I get error in consol:

          [mp3 @ 00000165A7B5A100] Could not find codec parameters for stream 1 (Video: png, none): unspecified size
          Consider increasing the value for the 'analyzeduration' (0) and 'probesize' (5000000) options
          Input #0, mp3, from 'C:/Users/Admin/AppData/Local/Temp/MM terminal.cRcedC.mp3':
            Metadata:
              artist          : Sound Clip
              title           : Военно-морской сигнал тревоги 
              encoder         : Lavf56.40.101
              date            : 2020
            Duration: 00:00:08.39, start: 0.011995, bitrate: 130 kb/s
            Stream #0:0: Audio: mp3 (mp3float), 44100 Hz, stereo, fltp, 128 kb/s
                Metadata:
                  encoder         : LAME3.97 
                Side data:
                  replaygain: track gain - -10.600000, track peak - unknown, album gain - unknown, album peak - unknown, 
            Stream #0:1: Video: png, none, 90k tbr, 90k tbn (attached pic)
                Metadata:
                  title           : Album cover
                  comment         : Cover (front)
          

          after:
          m_player change status on QMediaPlayer::LoadedMedia
          m_player change status on QMediaPlayer::BufferingMedia
          m_player change status on QMediaPlayer::BufferedMedia

          1 Reply Last reply
          0
          • jsulmJ jsulm

            @Mihaill Add error handling to your code to see whether there are any errors (https://doc.qt.io/archives/qt-5.15/qmediaplayer.html#error-1)
            Also connect a slot to https://doc.qt.io/archives/qt-5.15/qmediaplayer.html#stateChanged and see which state changes you have.

            I hope m_player is not a local variable which gets destroyed when its scope is gone...

            "Then I get eoor:" - I don't see any errors related to audio playback.

            M Offline
            M Offline
            Mihaill
            wrote last edited by
            #4

            @jsulm
            after QMediaPlayer::BufferedMedia m_player have:

            [25.07.2025 17:00:27.476 UTC+03:00][D]: -----m_player.duration() 8385
            
            [25.07.2025 17:00:27.478 UTC+03:00][D]: -----m_player.hasAudio() true
            
            [25.07.2025 17:00:27.479 UTC+03:00][D]: -----m_player.hasVideo() false
            
            [25.07.2025 17:00:27.479 UTC+03:00][D]: -----m_player.position() 0
            

            but m_player don't started

            1 Reply Last reply
            0
            • JoeCFDJ Offline
              JoeCFDJ Offline
              JoeCFD
              wrote last edited by JoeCFD
              #5

              try the following to see if it works or not
              QT_MEDIA_BACKEND=gstreamer ./your_application

              I guess you are using Qt6 and its default backend is FFmpeg. And check if you have installed FFmpeg.

              Multimedia module in Qt5 uses gstreamer.

              M 1 Reply Last reply
              0
              • JoeCFDJ JoeCFD

                try the following to see if it works or not
                QT_MEDIA_BACKEND=gstreamer ./your_application

                I guess you are using Qt6 and its default backend is FFmpeg. And check if you have installed FFmpeg.

                Multimedia module in Qt5 uses gstreamer.

                M Offline
                M Offline
                Mihaill
                wrote last edited by Mihaill
                #6

                @JoeCFD said in Don't play mp3:

                I guess you are using Qt6 and its default backend is FFmpeg. And check if you have installed FFmpeg.

                My computer have ffmpeg version 2024-10-07. And another mp3 is work. But me need play all possible mp3.
                And ffplay can play my file

                JonBJ 1 Reply Last reply
                0
                • M Mihaill

                  @JoeCFD said in Don't play mp3:

                  I guess you are using Qt6 and its default backend is FFmpeg. And check if you have installed FFmpeg.

                  My computer have ffmpeg version 2024-10-07. And another mp3 is work. But me need play all possible mp3.
                  And ffplay can play my file

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote last edited by
                  #7

                  @Mihaill
                  Qt cannot help if perchance ffmpeg cannot play some mp3 file. Have you tried the ffmpeg directly on the problem file? I do not see anywhere reported that ffmpeg cannot play certain mp3 files

                  Why are some MP3 files not playing?

                  If you find MP3 files are not playing on Windows, Android, or iOS, that may be caused by various reasons, including MP3 file corruption, incomplete downloading/transmission, code issues, hardware problems, unsupported media players, or computer viruses.17 Feb 2025

                  M 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @Mihaill
                    Qt cannot help if perchance ffmpeg cannot play some mp3 file. Have you tried the ffmpeg directly on the problem file? I do not see anywhere reported that ffmpeg cannot play certain mp3 files

                    Why are some MP3 files not playing?

                    If you find MP3 files are not playing on Windows, Android, or iOS, that may be caused by various reasons, including MP3 file corruption, incomplete downloading/transmission, code issues, hardware problems, unsupported media players, or computer viruses.17 Feb 2025

                    M Offline
                    M Offline
                    Mihaill
                    wrote last edited by
                    #8

                    @JonB but ffmpeg can play my file

                    JonBJ 1 Reply Last reply
                    0
                    • M Mihaill

                      @JonB but ffmpeg can play my file

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote last edited by
                      #9

                      @Mihaill
                      OIC, I misunderstood. Can only think: check the command line you use from ffmpeg explicitly when it works against the command line being executed from Qt? Check it is using the same ffmpeg executable from Qt as you use from command line?

                      M 1 Reply Last reply
                      0
                      • JonBJ JonB

                        @Mihaill
                        OIC, I misunderstood. Can only think: check the command line you use from ffmpeg explicitly when it works against the command line being executed from Qt? Check it is using the same ffmpeg executable from Qt as you use from command line?

                        M Offline
                        M Offline
                        Mihaill
                        wrote last edited by
                        #10

                        @JonB In command lyne I test this ile like this:

                        ffplay alarm.mp3
                        

                        In qt console after QMediaPlayer::LoadingMedia I get this error:

                        [mp3 @ 00000174EAE75600] Could not find codec parameters for stream 1 (Video: png, none): unspecified size
                        Consider increasing the value for the 'analyzeduration' (0) and 'probesize' (5000000) options
                        Input #0, mp3, from 'C:/QtProjects/qsingleteleshell/BModules/mmTerminal/sounds/alarm.mp3':
                          Metadata:
                            artist          : Sound Clip
                            title           : Военно-морской сигнал тревоги 
                            encoder         : Lavf56.40.101
                            date            : 2020
                          Duration: 00:00:08.39, start: 0.011995, bitrate: 130 kb/s
                          Stream #0:0: Audio: mp3 (mp3float), 44100 Hz, stereo, fltp, 128 kb/s
                              Metadata:
                                encoder         : LAME3.97 
                              Side data:
                                replaygain: track gain - -10.600000, track peak - unknown, album gain - unknown, album peak - unknown, 
                          Stream #0:1: Video: png, none, 90k tbr, 90k tbn (attached pic)
                              Metadata:
                                title           : Album cover
                                comment         : Cover (front)
                        
                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          Mihaill
                          wrote last edited by
                          #11

                          I find in log this text : Using Qt multimedia with FFmpeg version 7.1 LGPL version 2.1 or later

                          1 Reply Last reply
                          0
                          • M Offline
                            M Offline
                            Mihaill
                            wrote last edited by
                            #12

                            it's work with vlc

                            #pragma once
                            
                            #include <QObject>
                            #include <vlc/vlc.h>
                            #include <QString>
                            #include <QUrl>
                            #include <QTimer>
                            
                            class VlcAudioPlayer : public QObject
                            {
                                Q_OBJECT
                            public:
                                explicit VlcAudioPlayer(QObject* parent = nullptr);
                                ~VlcAudioPlayer();
                            
                                // Запустить воспроизведение аудиофайла по локальному пути
                                bool play(const QString& filePath);
                            
                                // Остановить воспроизведение
                                void stop();
                            
                                // Проверить, играет ли сейчас аудио
                                bool isPlaying() const;
                            
                            signals:
                                void started();
                                void stopped();
                                void finished();
                            
                            private slots:
                                void checkPlayback();
                            
                            private:
                                libvlc_instance_t* m_instance = nullptr;
                                libvlc_media_player_t* m_mediaPlayer = nullptr;
                                QTimer m_timer;
                            };
                            
                            #include "VlcAudioPlayer.h"
                            #include <QDebug>
                            
                            VlcAudioPlayer::VlcAudioPlayer(QObject* parent)
                                : QObject(parent)
                            {
                                const char* args[] = { "--no-xlib" };
                                m_instance = libvlc_new(1, args);
                                if (!m_instance) {
                                    qWarning() << "Failed to create libVLC instance";
                                }
                            
                                m_mediaPlayer = nullptr;
                            
                                // Таймер для проверки состояния воспроизведения
                                connect(&m_timer, &QTimer::timeout, this, &VlcAudioPlayer::checkPlayback);
                                m_timer.setInterval(200); // проверять каждые 200 мс
                            }
                            
                            VlcAudioPlayer::~VlcAudioPlayer()
                            {
                                if (m_mediaPlayer) {
                                    libvlc_media_player_stop(m_mediaPlayer);
                                    libvlc_media_player_release(m_mediaPlayer);
                                }
                                if (m_instance) {
                                    libvlc_release(m_instance);
                                }
                            }
                            
                            bool VlcAudioPlayer::play(const QString& filePath)
                            {
                                if (!m_instance) {
                                    qWarning() << "libVLC instance is null";
                                    return false;
                                }
                            
                                // Если уже играет, остановим
                                if (isPlaying()) {
                                    stop();
                                }
                            
                                // Преобразуем путь в URI
                                QUrl url = QUrl::fromLocalFile(filePath);
                                QString uri = url.toString();
                            
                                libvlc_media_t* media = libvlc_media_new_location(m_instance, uri.toUtf8().constData());
                                if (!media) {
                                    qWarning() << "Failed to create media from URI:" << uri;
                                    return false;
                                }
                            
                                if (m_mediaPlayer) {
                                    libvlc_media_player_stop(m_mediaPlayer);
                                    libvlc_media_player_release(m_mediaPlayer);
                                    m_mediaPlayer = nullptr;
                                }
                            
                                m_mediaPlayer = libvlc_media_player_new_from_media(media);
                                libvlc_media_release(media);
                            
                                if (!m_mediaPlayer) {
                                    qWarning() << "Failed to create media player";
                                    return false;
                                }
                            
                                if (libvlc_media_player_play(m_mediaPlayer) != 0) {
                                    qWarning() << "Failed to start playback";
                                    libvlc_media_player_release(m_mediaPlayer);
                                    m_mediaPlayer = nullptr;
                                    return false;
                                }
                            
                                emit started();
                                m_timer.start();
                            
                                return true;
                            }
                            
                            void VlcAudioPlayer::stop()
                            {
                                if (m_mediaPlayer && isPlaying()) {
                                    libvlc_media_player_stop(m_mediaPlayer);
                                    emit stopped();
                                }
                                m_timer.stop();
                            }
                            
                            bool VlcAudioPlayer::isPlaying() const
                            {
                                if (!m_mediaPlayer)
                                    return false;
                                return libvlc_media_player_is_playing(m_mediaPlayer) != 0;
                            }
                            
                            void VlcAudioPlayer::checkPlayback()
                            {
                                if (!m_mediaPlayer) {
                                    m_timer.stop();
                                    return;
                                }
                            
                                if (!isPlaying()) {
                                    m_timer.stop();
                                    emit finished();
                                }
                            }
                            
                            
                            1 Reply Last reply
                            0
                            • M Mihaill has marked this topic as solved

                            • Login

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