Reputation: 751
Problem: The following calls don't make QMediaPlayer play any sound.
player->setMedia(QUrl("qrc:/snd/coin-refund.mp3"));
player->play();
Where player
is of type QMediaPlayer*
.
Where the URL was generated using the QtCreator Copy URL option. So the file for sure is in the .qrc file.
Details:
I have a class derived from QObject
like this:
class MyClass : public QObject
{
Q_OBJECT
// some stuff
private:
QMediaPlayer* player;
}
A call to the QMediaPlayer standard constructor in the MyClass constructor like this...
MyClass::MyClass() :
player(new QMediaPlayer)
{
}
... causes the following error message on runtime (application compiles without any warnings)
QObject::startTimer: Timers can only be used with threads started with QThread
Removing the player removes this message (I haven't explicitly created any QThreads or QTimers).
In my .pro file I have :
QT += core gui webkitwidgets multimedia multimediawidgets widgets
Additional Information: I'm on Arch Linux, using QtCreator 4.2.2 and Qt 5.8.0
EDIT:
Upvotes: 1
Views: 2572
Reputation: 244252
The problem seems to be that the object does not start properly in the constructor, the solution I have found so far to create the object every time you want to do play()
.
void automaton::vendorSlot(const unsigned int buttonPressed)
{
player = new QMediaPlayer;
switch (buttonPressed)
[...]
Upvotes: 3