reset player if stuck

This commit is contained in:
j 2023-11-08 11:01:02 +01:00
parent 7e4c062a13
commit 3252392eb5

View file

@ -35,6 +35,7 @@ class Sync(Thread):
destination = "255.255.255.255" destination = "255.255.255.255"
reload_check = None reload_check = None
_pos = None _pos = None
_tick = 0
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.is_main = kwargs.get('mode', 'main') == 'main' self.is_main = kwargs.get('mode', 'main') == 'main'
@ -66,7 +67,6 @@ class Sync(Thread):
self.sync_to_main() self.sync_to_main()
self.ready = True self.ready = True
Thread.__init__(self) Thread.__init__(self)
self.daemon = True
self.start() self.start()
def run(self): def run(self):
@ -77,6 +77,13 @@ class Sync(Thread):
self.read_position_main() self.read_position_main()
#self.adjust_position() #self.adjust_position()
self.reload_playlist() self.reload_playlist()
if self._tick and abs(time.time() - self._tick) > 10:
logger.error("player is stuck")
self._tick = 0
self.mpv.loadlist(self.playlist)
self.mpv.playlist_play_index(0)
self.mpv.pause = False
self.mpv.wait_until_playing()
def q_binding(self, *args): def q_binding(self, *args):
self.stop() self.stop()
@ -89,6 +96,7 @@ class Sync(Thread):
self.sock = None self.sock = None
def time_pos_cb(self, pos, *args, **kwargs): def time_pos_cb(self, pos, *args, **kwargs):
self._tick = time.time()
if self.is_main: if self.is_main:
self.send_position_local() self.send_position_local()
elif self.ready: elif self.ready: