Skip to content

Commit

Permalink
MPRIS started working, fixed ellipse in label
Browse files Browse the repository at this point in the history
  • Loading branch information
Nokse22 committed Apr 12, 2024
1 parent 05b4b20 commit 5602aa3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
11 changes: 11 additions & 0 deletions src/lib/player_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ def _play_track(self, track):

self.playing_track = track
self.song_album = track.album

if len(self.tracks_to_play) > 0:
self.can_next = True
else:
self.can_next = False

if len(self.played_songs) > 0:
self.can_prev = True
else:
self.can_prev = False

self.emit("song-changed")

def play_next(self):
Expand Down
32 changes: 18 additions & 14 deletions src/mpris.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,22 +144,22 @@ def __init__(self, player, window):
self.__metadata["mpris:trackid"] = GLib.Variant(
"o", f"/Track/{track_id}"
)
self.__metadata["xesam:title"] = GLib.Variant(
"s", "Prova"
)
self.__metadata["xesam:album"] = GLib.Variant(
"s", _("Album")
)
self.__metadata["xesam:artist"] = GLib.Variant("as", [_("Artist")])

track = self.player.playing_track

if track:
self.__metadata["xesam:title"] = GLib.Variant("s", track.name)
self.__metadata["xesam:album"] = GLib.Variant("s", track.album)
self.__metadata["xesam:artist"] = GLib.Variant("as", [track.artist])

self.__bus = Gio.bus_get_sync(Gio.BusType.SESSION, None)
Gio.bus_own_name_on_connection(
self.__bus, self.__MPRIS_HIGH_TIDE, Gio.BusNameOwnerFlags.NONE, None, None
)
Server.__init__(self, self.__bus, self.__MPRIS_PATH)

# MainPlayer.get().connect("preset-changed", self._on_preset_changed)
# MainPlayer.get().connect("notify::playing", self._on_playing_changed)
self.player.connect("song-changed", self._on_preset_changed)
self.player.connect("play-changed", self._on_playing_changed)
# MainPlayer.get().connect("notify::volume", self._on_volume_changed)

def Raise(self):
Expand Down Expand Up @@ -263,19 +263,23 @@ def _get_status(self):
return "Paused"

def _on_preset_changed(self, *args):
self.__metadata["xesam:title"] = GLib.Variant("s", "Prova?")
self.__metadata["xesam:title"] = GLib.Variant("s", self.player.playing_track.name)
self.__metadata["xesam:album"] = GLib.Variant("s", self.player.playing_track.album.name)
self.__metadata["xesam:artist"] = GLib.Variant("as", [self.player.playing_track.artist.name])
self.__metadata["xesam:artUrl"] = GLib.Variant("s", f"tmp_img/{self.player.playing_track.album.id}.jpg")

changed_properties = {
"Metadata": GLib.Variant("a{sv}", self.__metadata),
"CanGoNext": GLib.Variant("b", True),
"CanGoPrevious": GLib.Variant("b", True),
"CanGoNext": GLib.Variant("b", self.player.can_next),
"CanGoPrevious": GLib.Variant("b", self.player.can_prev),
}
self.PropertiesChanged(self.__MPRIS_PLAYER_IFACE, changed_properties, [])

def _on_volume_changed(self, player, volume):
def _on_volume_changed(self, _player, volume):
self.PropertiesChanged(
self.__MPRIS_PLAYER_IFACE,
{
"Volume": GLib.Variant("d", MainPlayer.get().volume),
"Volume": GLib.Variant("d", self.player.volume),
},
[],
)
Expand Down
2 changes: 2 additions & 0 deletions src/ui/pages_ui/tracks_list_template.ui
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,15 @@
<object class="GtkLabel" id="_title_label2">
<property name="css-classes">title-1</property>
<property name="valign">start</property>
<property name="ellipsize">end</property>
<property name="label" bind-source="_title_label" bind-property="label"/>
</object>
</child>
<child>
<object class="GtkLabel" id="_first_subtitle_label2">
<property name="css-classes">dim-label</property>
<property name="valign">start</property>
<property name="ellipsize">end</property>
<property name="wrap">true</property>
<property name="justify">center</property>
<property name="label" bind-source="_first_subtitle_label" bind-property="label"/>
Expand Down
4 changes: 2 additions & 2 deletions src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ def __init__(self, **kwargs):

self.select_quality(self.settings.get_int("quality"))

MPRIS(self.player_object, self)

self.current_mix = None
self.player_object.current_song_index = 0
self.previous_time = 0
Expand All @@ -141,6 +139,8 @@ def __init__(self, **kwargs):
th.deamon = True
th.start()

MPRIS(self.player_object, self)

def on_logged_in(self):
print("on logged in")
self.favourite_tracks = self.session.user.favorites.tracks()
Expand Down

0 comments on commit 5602aa3

Please sign in to comment.