Skip to content

Commit c1e456e

Browse files
Plamperhaginrich
authored andcommitted
Added timer for go can-go-prev (Nokse22#188)
1 parent 2fb3174 commit c1e456e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/lib/player_object.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,12 @@ def _on_track_start(self, bus: Any, message: Any):
324324
self.seek(self.seek_after_sink_reload)
325325
self.seek_after_sink_reload = None
326326

327+
self.can_go_prev = len(self.played_songs) > 0
328+
# Only notify to deactivate
329+
if not self.can_go_prev:
330+
self.notify("can-go-prev")
331+
GLib.timeout_add(2000, self.previous_timer_callback)
332+
327333
def play_this(
328334
self, thing: Union[Mix, Album, Playlist, List[Track], Track], index: int = 0
329335
) -> None:
@@ -598,6 +604,11 @@ def play_previous(self):
598604
# if not in the first 2 seconds of the track restart song
599605
if self.query_position() > 2 * Gst.SECOND:
600606
self.seek(0)
607+
self.can_go_prev = len(self.played_songs) > 0
608+
# only notify when can't go to previous
609+
if not self.can_go_prev:
610+
self.notify("can-go-prev")
611+
GLib.timeout_add(2000, self.previous_timer_callback)
601612
return
602613

603614
if not self.played_songs:
@@ -609,6 +620,11 @@ def play_previous(self):
609620
self._tracks_to_play.insert(0, self.playing_track)
610621
self.play_track(track)
611622

623+
def previous_timer_callback(self):
624+
"""Send a notify Event after 2s of the song playing"""
625+
self.can_go_prev = True
626+
self.notify("can-go-prev")
627+
612628
def _update_shuffle_queue(self):
613629
if self.shuffle:
614630
self._shuffled_tracks_to_play = self._tracks_to_play.copy()

0 commit comments

Comments
 (0)