diff --git a/plugins/findthisdevice/findthisdevice_config.cpp b/plugins/findthisdevice/findthisdevice_config.cpp index fa18827a1..dbf8fc1e3 100644 --- a/plugins/findthisdevice/findthisdevice_config.cpp +++ b/plugins/findthisdevice/findthisdevice_config.cpp @@ -15,6 +15,10 @@ #include #include +#if QT_VERSION_MAJOR == 6 +#include +#endif + K_PLUGIN_FACTORY(FindThisDeviceConfigFactory, registerPlugin();) FindThisDeviceConfig::FindThisDeviceConfig(QObject *parent, const QVariantList &args) @@ -68,11 +72,20 @@ void FindThisDeviceConfig::playSound() qCWarning(KDECONNECT_PLUGIN_FINDTHISDEVICE) << "Not playing sound, no valid ring tone specified."; } else { QMediaPlayer *player = new QMediaPlayer; +#if QT_VERSION_MAJOR < 6 player->setAudioRole(QAudio::Role(QAudio::NotificationRole)); player->setMedia(soundURL); player->setVolume(100); player->play(); connect(player, &QMediaPlayer::stateChanged, player, &QObject::deleteLater); +#else + auto audioOutput = new QAudioOutput(); + audioOutput->setVolume(100); + player->setSource(soundURL); + player->setAudioOutput(audioOutput); + player->play(); + connect(player, &QMediaPlayer::playingChanged, player, &QObject::deleteLater); +#endif } } diff --git a/plugins/findthisdevice/findthisdeviceplugin.cpp b/plugins/findthisdevice/findthisdeviceplugin.cpp index a7db36284..37e214b1b 100644 --- a/plugins/findthisdevice/findthisdeviceplugin.cpp +++ b/plugins/findthisdevice/findthisdeviceplugin.cpp @@ -20,6 +20,10 @@ #include #include +#if QT_VERSION_MAJOR == 6 +#include +#endif + K_PLUGIN_CLASS_WITH_JSON(FindThisDevicePlugin, "kdeconnect_findthisdevice.json") FindThisDevicePlugin::FindThisDevicePlugin(QObject *parent, const QVariantList &args) @@ -42,9 +46,18 @@ bool FindThisDevicePlugin::receivePacket(const NetworkPacket &np) } QMediaPlayer *player = new QMediaPlayer; +#if QT_VERSION_MAJOR < 6 player->setAudioRole(QAudio::Role(QAudio::NotificationRole)); player->setMedia(soundURL); player->setVolume(100); +#else + auto audioOutput = new QAudioOutput(); + audioOutput->setVolume(100); + player->setSource(soundURL); + player->setAudioOutput(audioOutput); + connect(player, &QMediaPlayer::playingChanged, player, &QObject::deleteLater); +#endif + player->play(); #ifndef Q_OS_WIN const auto sinks = PulseAudioQt::Context::instance()->sinks(); @@ -55,7 +68,11 @@ bool FindThisDevicePlugin::receivePacket(const NetworkPacket &np) mutedSinks.append(sink); } } - connect(player, &QMediaPlayer::stateChanged, this, [player, mutedSinks] { +#if QT_VERSION_MAJOR < 6 + connect(player, &QMediaPlayer::stateChanged, this, [mutedSinks] { +#else + connect(player, &QMediaPlayer::playingChanged, this, [mutedSinks] { +#endif for (auto sink : qAsConst(mutedSinks)) { sink->setMuted(true); } @@ -63,7 +80,11 @@ bool FindThisDevicePlugin::receivePacket(const NetworkPacket &np) #endif player->play(); +#if QT_VERSION_MAJOR < 6 connect(player, &QMediaPlayer::stateChanged, player, &QObject::deleteLater); +#else + connect(player, &QMediaPlayer::playingChanged, player, &QObject::deleteLater); +#endif // TODO: ensure to use built-in loudspeakers return true;