[英]QMediaplayer: No sound
Problem: The following calls don't make QMediaPlayer play any sound. 问题:以下调用不会使QMediaPlayer播放任何声音。
player->setMedia(QUrl("qrc:/snd/coin-refund.mp3"));
player->play();
Where player
is of type QMediaPlayer*
. 其中player
是QMediaPlayer*
类型。 Where the URL was generated using the QtCreator Copy URL option. 使用QtCreator复制URL选项生成URL的位置。 So the file for sure is in the .qrc file. 因此,该文件肯定在.qrc文件中。
Details: 细节:
I have a class derived from QObject
like this: 我有一个从QObject
派生的类,如下所示:
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构造函数中调用QMediaPlayer标准构造函数...
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 QObject :: startTimer:计时器只能与以QThread启动的线程一起使用
Removing the player removes this message (I haven't explicitly created any QThreads or QTimers). 删除播放器将删除此消息(我尚未明确创建任何QThreads或QTimers)。
In my .pro file I have : 在我的.pro文件中,我有:
QT += core gui webkitwidgets multimedia multimediawidgets widgets
Additional Information: I'm on Arch Linux, using QtCreator 4.2.2 and Qt 5.8.0 附加信息:我在Arch Linux上,使用QtCreator 4.2.2和Qt 5.8.0
EDIT: 编辑:
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()
. 问题似乎是该对象无法在构造函数中正确启动,到目前为止,我找到的解决方案是每次您要执行play()
都创建该对象。
void automaton::vendorSlot(const unsigned int buttonPressed)
{
player = new QMediaPlayer;
switch (buttonPressed)
[...]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.