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