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. QMediaPlayer don't play sound from QByteArray in macOS
Qt 6.11 is out! See what's new in the release blog

QMediaPlayer don't play sound from QByteArray in macOS

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 5 Posters 3.9k Views 2 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
    ARASHz4
    wrote on last edited by ARASHz4
    #1

    Hi
    This is my code :

        QFile file("sound.mp3");
        file.open(QIODevice::ReadOnly);
        QByteArray arr = file.readAll();
    
        QMediaPlayer *player = new QMediaPlayer(this);
    
        QBuffer *buffer = new QBuffer(player);
        buffer->setData(arr);
        buffer->open(QIODevice::ReadOnly);
        player->setMedia(QMediaContent(),buffer);
    
        player->play();
    

    This code work in windows fine but in macOS sound don't play, i can just play sound from file in macOS

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

      Hi,

      From a quick look at the current macOS implementation, it seems that the device is not used in the backend.

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

      M 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        From a quick look at the current macOS implementation, it seems that the device is not used in the backend.

        M Offline
        M Offline
        merlinko
        wrote on last edited by
        #3

        @SGaist I have the same problem. Can you please explain what does that mean? It just does not work on mac?

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

          Yes, that's that. However, you don't need a QBuffer if you already load from a file. Just use it with QMediaPlayer..

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

          M 1 Reply Last reply
          0
          • SGaistS SGaist

            Yes, that's that. However, you don't need a QBuffer if you already load from a file. Just use it with QMediaPlayer..

            M Offline
            M Offline
            merlinko
            wrote on last edited by
            #5

            @SGaist But that is much slower :/ that is the problem

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mpergand
              wrote on last edited by mpergand
              #6

              Maybe as a alternative, you can use the MediaContent instead of a buffer for preloading sound files:

              QMediaPlayer* mp=new QMediaPlayer;
              mp->setMedia(QUrl::fromLocalFile("some.mp3"));
              
              QMediaContent mc=mp->media();  // get the MediaContent
              delete mp;
              
               mp=new QMediaPlayer;  // create a new MedaiPlayer
               mp->setMedia(mc);  // set the media with the previous content
              
              mp->setVolume(50);
              mp->play();
              

              Works for me with Qt 5.8, OSX 10.9

              [EDIT]
              no need of MediaPlayer for loading !

              QMediaContent(const QUrl &url)
              

              will work alone ;)

              1 Reply Last reply
              3
              • V Offline
                V Offline
                VaL Doroshchuk
                wrote on last edited by
                #7

                https://bugreports.qt.io/browse/QTBUG-69101

                1 Reply Last reply
                4

                • Login

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