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
Forum Updated to NodeBB v4.3 + New Features

QMediaPlayer don't play sound from QByteArray in macOS

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 5 Posters 2.5k 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 7 Dec 2017, 21:57 last edited by ARASHz4 12 Jul 2017, 21:58
    #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
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 9 Dec 2017, 22:48 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 10 Jan 2018, 12:12
      0
      • S SGaist
        9 Dec 2017, 22:48

        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 10 Jan 2018, 12:12 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
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 10 Jan 2018, 21:07 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 11 Jan 2018, 09:42
          0
          • S SGaist
            10 Jan 2018, 21:07

            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 11 Jan 2018, 09:42 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 11 Jan 2018, 15:52 last edited by mpergand 1 Nov 2018, 16:11
              #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 27 Jun 2018, 09:43 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