Commit 221b096b authored by kroovy's avatar kroovy
Browse files

implement stop api

parent 7001182b
...@@ -11,6 +11,7 @@ class Player(threading.Thread): ...@@ -11,6 +11,7 @@ class Player(threading.Thread):
def __init__(self): def __init__(self):
super().__init__(target=self) super().__init__(target=self)
self._logger = logging.getLogger("player") self._logger = logging.getLogger("player")
self.running = True;
def play(self, filename): def play(self, filename):
self._logger.info("start playing {}".format(filename)) self._logger.info("start playing {}".format(filename))
...@@ -26,7 +27,7 @@ class Player(threading.Thread): ...@@ -26,7 +27,7 @@ class Player(threading.Thread):
output=True output=True
) )
data = wave_file.readframes(chunk) data = wave_file.readframes(chunk)
while len(data) > 0: while len(data) > 0 and self.running:
stream.write(data) stream.write(data)
data = wave_file.readframes(chunk) data = wave_file.readframes(chunk)
......
...@@ -35,6 +35,8 @@ def play(file): ...@@ -35,6 +35,8 @@ def play(file):
If queing is successfull return the position in the queue. Play the If queing is successfull return the position in the queue. Play the
oldest song in the queue. """ oldest song in the queue. """
api.player.player.running = True;
if api.index.is_indexed(file): if api.index.is_indexed(file):
try: try:
api.queue.q.put(file, False) api.queue.q.put(file, False)
...@@ -44,3 +46,15 @@ def play(file): ...@@ -44,3 +46,15 @@ def play(file):
return jsonify({"queue_size": api.queue.q.qsize()}) return jsonify({"queue_size": api.queue.q.qsize()})
else: else:
return abort(404) return abort(404)
@web.route("/stop/")
def stop():
""" Immediatly stop the playing song. """
#TODO
api.player.player.running = False;
while (api.queue.qsize() != 0):
print(">>> qsize = {}".format(api.queue.qsize())
api.queue.get()
return "stopped"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment