shutdown sync server if player fails

This commit is contained in:
j 2024-01-15 11:12:48 +01:00
parent c2c1a711d9
commit c2852838dd

View file

@ -57,11 +57,12 @@ class Player(Thread):
current = ''
playlist_items = 260
def __init__(self, peer, player, playlist, prefix):
def __init__(self, peer, player, playlist, prefix, server):
self.peer = peer
self.playlist = playlist
self.prefix = prefix
self.player = player
self.server = server
self.queue = Queue()
Thread.__init__(self)
self.daemon = True
@ -72,15 +73,20 @@ class Player(Thread):
self.position, self.playlist_items = update_playlist(self.playlist, self.prefix, position=self.get_position())
logger.debug("load playlist")
self.player.loadlist(self.playlist)
self.player.pause = True
while self.running:
logger.debug("play")
self.play()
self.position = (self.position + 1) % self.playlist_items
logger.debug("ping")
self.ping()
logger.debug("wait")
self.queue.get()
try:
self.player.pause = True
while self.running:
logger.debug("play")
self.play()
self.position = (self.position + 1) % self.playlist_items
logger.debug("ping")
self.ping()
logger.debug("wait")
self.queue.get()
except:
logger.error("playback failed")
self.running = False
self.server.shutdown()
def play(self):
self.playing = True
@ -157,7 +163,7 @@ def main():
listen = '0.0.0.0'
server = ThreadingUDPServer((listen, args.port), Handler)
server.allow_reuse_address = True
server.player = Player(peer, player, args.playlist, args.prefix)
server.player = Player(peer, player, args.playlist, args.prefix, server)
player.register_key_binding('q', server.q_binding)
logger.debug("listen on %s...", args.port)