QMediaPlayer don't play sound from QByteArray in macOS

  • Hi
    This is my code :

        QFile file("sound.mp3");
        QByteArray arr = file.readAll();
        QMediaPlayer *player = new QMediaPlayer(this);
        QBuffer *buffer = new QBuffer(player);

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

  • Lifetime Qt Champion


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

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

  • Lifetime Qt Champion

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

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

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

    QMediaPlayer* mp=new QMediaPlayer;
    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

    Works for me with Qt 5.8, OSX 10.9

    no need of MediaPlayer for loading !

    QMediaContent(const QUrl &url)

    will work alone ;)

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.