Implement and document player_prop callback.
This commit is contained in:
parent
00a434774d
commit
3c19752ad3
@ -13,6 +13,7 @@ class Dbus:
|
|||||||
path_dbus = "/org/freedesktop/DBus"
|
path_dbus = "/org/freedesktop/DBus"
|
||||||
obj_player = "org.mpris.MediaPlayer2"
|
obj_player = "org.mpris.MediaPlayer2"
|
||||||
path_player = "/org/mpris/MediaPlayer2"
|
path_player = "/org/mpris/MediaPlayer2"
|
||||||
|
intf_props = obj_dbus + ".Properties"
|
||||||
intf_player = obj_player + ".Player"
|
intf_player = obj_player + ".Player"
|
||||||
|
|
||||||
|
|
||||||
@ -44,10 +45,15 @@ class NowPlaying(IntervalModule):
|
|||||||
* ``playpause`` — Plays if paused or stopped, otherwise pauses.
|
* ``playpause`` — Plays if paused or stopped, otherwise pauses.
|
||||||
* ``next_song`` — Goes to next track in the playlist.
|
* ``next_song`` — Goes to next track in the playlist.
|
||||||
* ``player_command`` — Invoke a command with the `MediaPlayer2.Player` \
|
* ``player_command`` — Invoke a command with the `MediaPlayer2.Player` \
|
||||||
interface. The method name and its arguments are appended as list elements. \
|
interface. The method name and its arguments are appended as list elements.
|
||||||
Documentation for available methods can be found at \
|
* ``player_prop`` — Get or set a property of the `MediaPlayer2.Player` \
|
||||||
|
interface. Append the property name to get, or the name and a value to set.
|
||||||
|
|
||||||
|
`MediaPlayer2.Player` methods and properties are documented at \
|
||||||
https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html
|
https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html
|
||||||
|
|
||||||
|
Your player may not support the full interface.
|
||||||
|
|
||||||
Example module registration with callbacks:
|
Example module registration with callbacks:
|
||||||
|
|
||||||
::
|
::
|
||||||
@ -55,6 +61,7 @@ https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html
|
|||||||
status.register("now_playing",
|
status.register("now_playing",
|
||||||
on_leftclick=["player_command", "PlayPause"],
|
on_leftclick=["player_command", "PlayPause"],
|
||||||
on_rightclick=["player_command", "Stop"],
|
on_rightclick=["player_command", "Stop"],
|
||||||
|
on_middleclick=["player_prop", "Shuffle", True],
|
||||||
on_upscroll=["player_command", "Seek", -10000000],
|
on_upscroll=["player_command", "Seek", -10000000],
|
||||||
on_downscroll=["player_command", "Seek", +10000000])
|
on_downscroll=["player_command", "Seek", +10000000])
|
||||||
|
|
||||||
@ -127,7 +134,7 @@ https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html
|
|||||||
def run(self):
|
def run(self):
|
||||||
try:
|
try:
|
||||||
player = self.get_player()
|
player = self.get_player()
|
||||||
properties = dbus.Interface(player, Dbus.obj_dbus + ".Properties")
|
properties = dbus.Interface(player, Dbus.intf_props)
|
||||||
|
|
||||||
def get_prop(name, default=None):
|
def get_prop(name, default=None):
|
||||||
try:
|
try:
|
||||||
@ -209,3 +216,16 @@ https://specifications.freedesktop.org/mpris-spec/latest/Player_Interface.html
|
|||||||
return
|
return
|
||||||
except dbus.exceptions.DBusException:
|
except dbus.exceptions.DBusException:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def player_prop(self, name, value=None):
|
||||||
|
try:
|
||||||
|
properties = dbus.Interface(self.get_player(), Dbus.intf_props)
|
||||||
|
# None/null/nil implies get because it's not a valid DBus datatype.
|
||||||
|
if value is None:
|
||||||
|
return properties.Get(Dbus.intf_player, name)
|
||||||
|
else:
|
||||||
|
properties.Set(Dbus.intf_player, name, value)
|
||||||
|
except NoPlayerException:
|
||||||
|
return
|
||||||
|
except dbus.exceptions.DBusException:
|
||||||
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user