forked from Wobbl/Wobuzz
MPRIS: Got everything necessary working. (I think.)
This commit is contained in:
parent
f23530628c
commit
1f149a25a3
10 changed files with 333 additions and 58 deletions
|
@ -1,11 +1,13 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from threading import Thread
|
||||
from jeepney import DBusAddress
|
||||
from jeepney.bus_messages import message_bus
|
||||
from jeepney.io.blocking import DBusConnection, open_dbus_connection
|
||||
|
||||
from .utils import *
|
||||
from .dbus_properties import DBusProperties
|
||||
from .dbus_introspectable import DBUSIntrospectable
|
||||
from .mpris_root import MPRISRoot
|
||||
from .mpris_player import MPRISPlayer
|
||||
|
||||
|
@ -15,6 +17,7 @@ class MPRISServer:
|
|||
self.app = app
|
||||
|
||||
self.properties_interface = DBusProperties(self, PROPERTIES_INTERFACE)
|
||||
self.introspection_interface = DBUSIntrospectable(self, INTROSPECTION_INTERFACE)
|
||||
self.root_interface = MPRISRoot(self, MPRIS_ROOT_INTERFACE)
|
||||
self.player_interface = MPRISPlayer(self, MPRIS_PLAYER_INTERFACE)
|
||||
|
||||
|
@ -51,6 +54,9 @@ class MPRISServer:
|
|||
if interface == PROPERTIES_INTERFACE:
|
||||
self.properties_interface.handle_message(msg)
|
||||
|
||||
elif interface == INTROSPECTION_INTERFACE:
|
||||
self.introspection_interface.handle_message(msg)
|
||||
|
||||
elif interface == MPRIS_ROOT_INTERFACE:
|
||||
self.root_interface.handle_message(msg)
|
||||
|
||||
|
@ -58,11 +64,30 @@ class MPRISServer:
|
|||
self.player_interface.handle_message(msg)
|
||||
|
||||
def on_playstate_update(self):
|
||||
current_playlist = self.app.player.current_playlist
|
||||
player = self.app.player
|
||||
current_playlist = player.current_playlist
|
||||
|
||||
if current_playlist is not None and current_playlist.current_track is not None:
|
||||
current_track = current_playlist.current_track
|
||||
|
||||
self.player_interface.metadata["xesam:title"] = ("s", current_track.metadata.title)
|
||||
art_path = self.app.utils.tmp_path + "/cover_cache/" + current_track.metadata.path.split("/")[-1][:-4]
|
||||
|
||||
self.properties_interface.properties_changed(MPRIS_PLAYER_INTERFACE)
|
||||
# metadata milli to microseconds --↓
|
||||
self.player_interface.metadata["mpris:length"] = ("x", current_track.duration * 1000)
|
||||
self.player_interface.metadata["mpris:artUrl"] = ("s", "file://" + art_path)
|
||||
self.player_interface.metadata["xesam:title"] = ("s", current_track.metadata.title)
|
||||
self.properties_interface.properties_changed(MPRIS_PLAYER_INTERFACE, "Metadata")
|
||||
|
||||
if player.playing:
|
||||
if player.paused:
|
||||
playback_status = "Paused"
|
||||
|
||||
else:
|
||||
playback_status = "Playing"
|
||||
|
||||
else:
|
||||
playback_status = "Stopped"
|
||||
|
||||
self.player_interface.playback_status = playback_status
|
||||
|
||||
self.properties_interface.properties_changed(MPRIS_PLAYER_INTERFACE, "PlaybackStatus")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue