home · contact · privacy
Restart playlist after ending of last file.
authorChristian Heller <c.heller@plomlompom.de>
Tue, 17 Dec 2024 00:29:34 +0000 (01:29 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Tue, 17 Dec 2024 00:29:34 +0000 (01:29 +0100)
src/ytplom/misc.py

index 3a0be6dc26d6915b885757b904880c03428d7e3a..81406d06ec18bb6ffdf531d4e888e2f5afdd038b 100644 (file)
@@ -568,6 +568,7 @@ class Player:
         - build MPV's internal playlist from .playlist
         - bind starting of files to ._signal_update and setting ._idx to MPV's
           own playlist position index
+        - bind ending last file to re-starting at playlist start
         - start playing
         """
         self._mpv = MPV(input_default_bindings=True,
@@ -582,6 +583,13 @@ class Player:
             self._idx = self._mpv.playlist_pos
             self._signal_update()
 
+        @self._mpv.event_callback('end-file')
+        def on_end_file(event) -> None:
+            if (b'eof' == event.as_dict()['reason']
+                    and self._idx + 1 == len(self.playlist)):
+                self._idx = 0
+                self._play_at_index()
+
         @self._mpv.event_callback('shutdown')
         def on_shutdown(_) -> None:
             self._kill_queue.put(True)