replace phonon with QtMultimedia

This commit is contained in:
Piyush Aggarwal 2019-04-30 16:24:09 +00:00 committed by Nicolas Fella
parent 459a1992e5
commit 5b73c081da
5 changed files with 18 additions and 23 deletions

View file

@ -48,12 +48,7 @@ if (NOT ZSH_AUTOCOMPLETE_DIR)
set(ZSH_AUTOCOMPLETE_DIR "${CMAKE_INSTALL_PREFIX}/share/zsh/site-functions")
endif()
find_package(Phonon4Qt5 4.9.0 NO_MODULE)
set_package_properties(Phonon4Qt5 PROPERTIES
DESCRIPTION "Qt-based audio library"
TYPE OPTIONAL
PURPOSE "Required for Find My Device plugin"
)
find_package(Qt5Multimedia)
set_package_properties(KF5Kirigami2 PROPERTIES
DESCRIPTION "QtQuick plugins to build user interfaces based on KDE UX guidelines"

View file

@ -24,7 +24,7 @@ if(NOT SAILFISHOS)
add_subdirectory(sftp)
endif()
if(Phonon4Qt5_FOUND)
if(Qt5Multimedia_FOUND)
add_subdirectory(findthisdevice)
endif()
endif()

View file

@ -1,5 +1,3 @@
include_directories(${PHONON_INCLUDE_DIR})
set(kdeconnect_findthisdevice_SRCS
findthisdeviceplugin.cpp
)
@ -10,8 +8,8 @@ kdeconnect_add_plugin(kdeconnect_findthisdevice
target_link_libraries(kdeconnect_findthisdevice
kdeconnectcore
${PHONON_LIBRARIES}
Qt5::Core
Qt5::Multimedia
Qt5::DBus
)
@ -22,7 +20,7 @@ ki18n_wrap_ui(kdeconnect_findthisdevice_config_SRCS findthisdevice_config.ui)
add_library(kdeconnect_findthisdevice_config MODULE ${kdeconnect_findthisdevice_config_SRCS})
target_link_libraries(kdeconnect_findthisdevice_config
kdeconnectpluginkcm
${PHONON_LIBRARIES}
Qt5::Multimedia
KF5::I18n
KF5::CoreAddons
KF5::ConfigWidgets

View file

@ -22,13 +22,12 @@
#include "findthisdeviceplugin.h"
#include "ui_findthisdevice_config.h"
// Phonon
#include <phonon/mediaobject.h>
// KF
#include <KLocalizedString>
#include <KPluginFactory>
// Qt
#include <QStandardPaths>
#include <QMediaPlayer>
K_PLUGIN_FACTORY(FindThisDeviceConfigFactory, registerPlugin<FindThisDeviceConfig>();)
@ -108,10 +107,13 @@ void FindThisDeviceConfig::playSound()
}
soundURL.clear();
}
QMediaPlayer* player = new QMediaPlayer;
player->setAudioRole(QAudio::Role(QAudio::NotificationRole));
player->setMedia(soundURL);
player->setVolume(100);
player->play();
connect(player, &QMediaPlayer::stateChanged, player, &QObject::deleteLater);
Phonon::MediaObject *media = Phonon::createPlayer(Phonon::NotificationCategory, soundURL);
media->play();
connect(media, SIGNAL(finished()), media, SLOT(deleteLater()));
}

View file

@ -20,8 +20,6 @@
#include "findthisdeviceplugin.h"
// Phonon
#include <phonon/mediaobject.h>
// KF
#include <KPluginFactory>
// Qt
@ -29,7 +27,7 @@
#include <QStandardPaths>
#include <QFile>
#include <QUrl>
#include <QMediaPlayer>
K_PLUGIN_FACTORY_WITH_JSON(KdeConnectPluginFactory, "kdeconnect_findthisdevice.json",
registerPlugin<FindThisDevicePlugin>();)
@ -88,10 +86,12 @@ bool FindThisDevicePlugin::receivePacket(const NetworkPacket& np)
return true;
}
Phonon::MediaObject *media = Phonon::createPlayer(Phonon::NotificationCategory, soundURL); // or CommunicationCategory?
media->play();
connect(media, &Phonon::MediaObject::finished, media, &QObject::deleteLater);
QMediaPlayer* player = new QMediaPlayer;
player->setAudioRole(QAudio::Role(QAudio::NotificationRole));
player->setMedia(soundURL);
player->setVolume(100);
player->play();
connect(player, &QMediaPlayer::stateChanged, player, &QObject::deleteLater);
// TODO: by-pass volume settings in case it is muted
// TODO: ensure to use built-in loudspeakers