shutdown sync server if player fails
This commit is contained in:
parent
c2c1a711d9
commit
c2852838dd
1 changed files with 17 additions and 11 deletions
|
@ -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,6 +73,7 @@ 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)
|
||||||
|
try:
|
||||||
self.player.pause = True
|
self.player.pause = True
|
||||||
while self.running:
|
while self.running:
|
||||||
logger.debug("play")
|
logger.debug("play")
|
||||||
|
@ -81,6 +83,10 @@ class Player(Thread):
|
||||||
self.ping()
|
self.ping()
|
||||||
logger.debug("wait")
|
logger.debug("wait")
|
||||||
self.queue.get()
|
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)
|
||||||
|
|
Loading…
Reference in a new issue