I have modified the Qt Media Player Example, trying to get QMediaGaplessPlaybackControl for a crossfade effect.
Here is my code:
auto service = m_player->service();
auto cc = service->requestControl("org.qt-project.qt.mediaplayercontrol/5.0");
Q_ASSERT(cc != nullptr);
QMessageBox::information(this, "", cc->metaObject()->className());
QMediaGaplessPlaybackControl* control = qobject_cast<QMediaGaplessPlaybackControl*>(cc);
Q_ASSERT(control != nullptr);
The problem is, that when I request the control, a nullptr
is returned. Does anyone know why?
I'm using Qt 5.11 on Windows with MSVC compiler.
The documentation of QMediaService is explicit about how to obtain a pointer to the media service's QMediaControl implementation:
auto cc = qobject_cast<QMediaPlayerControl *>(service->requestControl("org.qt-project.qt.mediaplayercontrol/5.0"));
So, in order to get cc
as QMediaGaplessPlaybackControl change:
auto cc = service->requestControl("org.qt-project.qt.mediagaplessplaybackcontrol/5.0");
to:
auto *cc = static_cast<QMediaGaplessPlaybackControl *>(qobject_cast<QMediaControl *>(service->requestControl("org.qt-project.qt.mediaplayercontrol/5.0")));