1
votes

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:

github link

ldd output (pastebin)

1
Have you installed the codecs for mp3? I am using Archlinux, Qt 5.8 and I have no problems ... you could help better if you can share your project via github, dropbox or similar.eyllanesc
You could run: ldd your_executable and show what you get.eyllanesc
@eyllanesc added github link as requested.Alex
@eyllanesc added ldd outputAlex

1 Answers

3
votes

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)
    [...]