简体   繁体   中英

QMediaplayer: No sound

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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM