This commit is contained in:
Nicolas Fella 2020-01-21 02:55:46 +00:00 committed by Aleix Pol Gonzalez
parent 6025f7cc48
commit e0d5927bca
3 changed files with 119 additions and 13 deletions

View file

@ -8,6 +8,8 @@ else()
) )
endif() endif()
qt5_add_dbus_interface(kdeconnect_pausemusic_SRCS org.mpris.MediaPlayer2.Player.xml mprisplayer)
kdeconnect_add_plugin(kdeconnect_pausemusic JSON kdeconnect_pausemusic.json SOURCES ${kdeconnect_pausemusic_SRCS}) kdeconnect_add_plugin(kdeconnect_pausemusic JSON kdeconnect_pausemusic.json SOURCES ${kdeconnect_pausemusic_SRCS})
target_link_libraries(kdeconnect_pausemusic target_link_libraries(kdeconnect_pausemusic

View file

@ -0,0 +1,108 @@
<?xml version="1.0" ?>
<node xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0">
<interface name="org.mpris.MediaPlayer2.Player">
<method name="Next" tp:name-for-bindings="Next">
</method>
<method name="Previous" tp:name-for-bindings="Previous">
</method>
<method name="Pause" tp:name-for-bindings="Pause">
</method>
<method name="PlayPause" tp:name-for-bindings="PlayPause">
</method>
<method name="Stop" tp:name-for-bindings="Stop">
</method>
<method name="Play" tp:name-for-bindings="Play">
</method>
<method name="Seek" tp:name-for-bindings="Seek">
<arg direction="in" type="x" name="Offset" tp:type="Time_In_Us">
</arg>
</method>
<method name="SetPosition" tp:name-for-bindings="Set_Position">
<arg direction="in" type="o" tp:type="Track_Id" name="TrackId">
</arg>
<arg direction="in" type="x" tp:type="Time_In_Us" name="Position">
</arg>
</method>
<method name="OpenUri" tp:name-for-bindings="Open_Uri">
<arg direction="in" type="s" tp:type="Uri" name="Uri">
</arg>
</method>
<property name="PlaybackStatus" tp:name-for-bindings="Playback_Status" type="s" tp:type="Playback_Status" access="read">
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="true"/>
</property>
<property name="LoopStatus" type="s" access="readwrite"
tp:name-for-bindings="Loop_Status" tp:type="Loop_Status">
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="true"/>
</property>
<property name="Rate" tp:name-for-bindings="Rate" type="d" tp:type="Playback_Rate" access="readwrite">
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="true"/>
</property>
<property name="Shuffle" tp:name-for-bindings="Shuffle" type="b" access="readwrite">
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="true"/>
</property>
<property name="Metadata" tp:name-for-bindings="Metadata" type="a{sv}" tp:type="Metadata_Map" access="read">
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="true"/>
<annotation name="org.qtproject.QtDBus.QtTypeName" value="QVariantMap"/>
</property>
<property name="Volume" type="d" tp:type="Volume" tp:name-for-bindings="Volume" access="readwrite">
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="true" />
</property>
<property name="Position" type="x" tp:type="Time_In_Us" tp:name-for-bindings="Position" access="read">
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="false"/>
</property>
<property name="MinimumRate" tp:name-for-bindings="Minimum_Rate" type="d" tp:type="Playback_Rate" access="read">
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="true"/>
</property>
<property name="MaximumRate" tp:name-for-bindings="Maximum_Rate" type="d" tp:type="Playback_Rate" access="read">
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="true"/>
</property>
<property name="CanGoNext" tp:name-for-bindings="Can_Go_Next" type="b" access="read">
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="true"/>
</property>
<property name="CanGoPrevious" tp:name-for-bindings="Can_Go_Previous" type="b" access="read">
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="true"/>
</property>
<property name="CanPlay" tp:name-for-bindings="Can_Play" type="b" access="read">
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="true"/>
</property>
<property name="CanPause" tp:name-for-bindings="Can_Pause" type="b" access="read">
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="true"/>
</property>
<property name="CanSeek" tp:name-for-bindings="Can_Seek" type="b" access="read">
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="true"/>
</property>
<property name="CanControl" tp:name-for-bindings="Can_Control" type="b" access="read">
<annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="false"/>
</property>
<signal name="Seeked" tp:name-for-bindings="Seeked">
<arg name="Position" type="x" tp:type="Time_In_Us">
</arg>
</signal>
</interface>
</node>
<!-- vim:set sw=2 sts=2 et ft=xml: -->

View file

@ -20,16 +20,12 @@
#include "pausemusicplugin.h" #include "pausemusicplugin.h"
#include <QDBusInterface>
#include <QDBusConnectionInterface>
#include <QDBusMessage>
#include <QDBusReply>
#include <KPluginFactory> #include <KPluginFactory>
#include <PulseAudioQt/Context> #include <PulseAudioQt/Context>
#include <PulseAudioQt/Sink> #include <PulseAudioQt/Sink>
#include <dbushelper.h> #include <dbushelper.h>
#include "mprisplayer.h"
//In older Qt released, qAsConst isnt available //In older Qt released, qAsConst isnt available
#include "qtcompat_p.h" #include "qtcompat_p.h"
@ -80,15 +76,15 @@ bool PauseMusicPlugin::receivePacket(const NetworkPacket& np)
const QStringList interfaces = DBusHelper::sessionBus().interface()->registeredServiceNames().value(); const QStringList interfaces = DBusHelper::sessionBus().interface()->registeredServiceNames().value();
for (const QString& iface : interfaces) { for (const QString& iface : interfaces) {
if (iface.startsWith(QLatin1String("org.mpris.MediaPlayer2"))) { if (iface.startsWith(QLatin1String("org.mpris.MediaPlayer2"))) {
QDBusInterface mprisInterface(iface, QStringLiteral("/org/mpris/MediaPlayer2"), QStringLiteral("org.mpris.MediaPlayer2.Player")); OrgMprisMediaPlayer2PlayerInterface mprisInterface(iface, QStringLiteral("/org/mpris/MediaPlayer2"), DBusHelper::sessionBus());
QString status = mprisInterface.property("PlaybackStatus").toString(); QString status = mprisInterface.playbackStatus();
if (status == QLatin1String("Playing")) { if (status == QLatin1String("Playing")) {
if (!pausedSources.contains(iface)) { if (!pausedSources.contains(iface)) {
pausedSources.insert(iface); pausedSources.insert(iface);
if (mprisInterface.property("CanPause").toBool()) { if (mprisInterface.canPause()) {
mprisInterface.asyncCall(QStringLiteral("Pause")); mprisInterface.Pause();
} else { } else {
mprisInterface.asyncCall(QStringLiteral("Stop")); mprisInterface.Stop();
} }
} }
} }
@ -113,8 +109,8 @@ bool PauseMusicPlugin::receivePacket(const NetworkPacket& np)
if (pause && !pausedSources.empty()) { if (pause && !pausedSources.empty()) {
for (const QString& iface : qAsConst(pausedSources)) { for (const QString& iface : qAsConst(pausedSources)) {
QDBusInterface mprisInterface(iface, QStringLiteral("/org/mpris/MediaPlayer2"), QStringLiteral("org.mpris.MediaPlayer2.Player")); OrgMprisMediaPlayer2PlayerInterface mprisInterface(iface, QStringLiteral("/org/mpris/MediaPlayer2"), DBusHelper::sessionBus());
mprisInterface.asyncCall(QStringLiteral("Play")); mprisInterface.Play();
} }
pausedSources.clear(); pausedSources.clear();
} }