Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved QMediaPlayer don't play sound from QByteArray in macOS

    General and Desktop
    5
    7
    2024
    Loading More Posts
    • 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
      ARASHz4 last edited by ARASHz4

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • M
          merlinko @SGaist last edited by

          @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 Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            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 Reply Quote 0
            • M
              merlinko @SGaist last edited by

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

              1 Reply Last reply Reply Quote 0
              • M
                mpergand last edited by mpergand

                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 Reply Quote 3
                • V
                  VaL Doroshchuk last edited by

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

                  1 Reply Last reply Reply Quote 4
                  • First post
                    Last post