QMediaPlayer don't play sound from QByteArray in macOS
-
wrote on 7 Dec 2017, 21:57 last edited by ARASHz4 12 Jul 2017, 21:58
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
-
Hi,
From a quick look at the current macOS implementation, it seems that the device is not used in the backend.
-
Hi,
From a quick look at the current macOS implementation, it seems that the device is not used in the backend.
-
Yes, that's that. However, you don't need a QBuffer if you already load from a file. Just use it with QMediaPlayer..
-
Yes, that's that. However, you don't need a QBuffer if you already load from a file. Just use it with QMediaPlayer..
-
wrote on 11 Jan 2018, 15:52 last edited by mpergand 1 Nov 2018, 16:11
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 ;)
-
wrote on 27 Jun 2018, 09:43 last edited by