auto advance, repeats, play on load (not tested)

This commit is contained in:
michael-grace 2020-11-03 01:07:25 +00:00
parent ec6d3b0854
commit f96dbf5f36
2 changed files with 93 additions and 13 deletions

View file

@ -52,7 +52,9 @@ class Player():
"pos_true": 0,
"remaining": 0,
"length": 0,
"loop": False,
"auto_advance": True,
"repeat": "NONE", #NONE, ONE or ALL
"play_on_load": False,
"output": None,
"show_plan": []
}
@ -114,6 +116,8 @@ class Player():
res = json.dumps(state)
return res
### Audio Playout Related Methods
def play(self, pos=0):
# if not self.isPlaying:
try:
@ -172,6 +176,35 @@ class Player():
self._updateState(pos=pos)
return True
def set_auto_advance(self, message: int) -> bool:
if message == 0:
self.state.update("auto_advance", False)
return True # It did it
elif message == 1:
self.state.update("auto_advance", True)
return True
else:
return False
def set_repeat(self, message: str) -> bool:
if message in ["ALL", "ONE", "NONE"]:
self.state.update("repeat", message)
return True
else:
return False
def set_play_on_load(self, message: int) -> bool:
if message == 0:
self.state.update("play_on_load", False)
return True # It did it
elif message == 1:
self.state.update("play_on_load", True)
return True
else:
return False
### Show Plan Related Methods
def add_to_plan(self, new_item: Dict[str, any]) -> bool:
self.state.update("show_plan", self.state.state["show_plan"] + [PlanObject(new_item)])
return True
@ -270,6 +303,31 @@ class Player():
self.state.update("remaining", self.state.state["length"] - self.state.state["pos_true"])
if self.state.state["remaining"] == 0:
# Track has ended
print("Finished", self.state.state["loaded_item"].name)
# Repeat 1
if self.state.state["repeat"] == "ONE":
self.play()
# Auto Advance
elif self.state.state["auto_advance"]:
for i in range(len(self.state.state["show_plan"])):
if self.state.state["show_plan"][i].timeslotitemid == self.state.state["loaded_item"].timeslotitemid:
if len(self.state.state["show_plan"]) > i+1:
self.load(self.state.state["show_plan"][i+1].timeslotitemid)
break
# Repeat All
elif self.state.state["repeat"] == "ALL":
self.load(self.state.state["show_plan"][0].timeslotitemid)
# Play on Load
if self.state.state["play_on_load"]:
self.play()
def _retMsg(self, msg, okay_str=False):
response = self.last_msg + ":"
if msg == True:
@ -339,15 +397,22 @@ class Player():
elif self.isInit:
message_types: Dict[str, Callable[any, bool]] = { # TODO Check Types
"STATUS": lambda: self._retMsg(self.status, True),
# Audio Playout
"PLAY": lambda: self._retMsg(self.play()),
"PAUSE": lambda: self._retMsg(self.pause()),
"UNPAUSE": lambda: self._retMsg(self.unpause()),
"STOP": lambda: self._retMsg(self.stop()),
"SEEK": lambda: self._retMsg(self.seek(float(self.last_msg.split(":")[1]))),
"AUTOADVANCE": lambda: self._retMsg(self.set_auto_advance(int(self.last_msg.split(":")[1]))),
"REPEAT": lambda: self._retMsg(self.set_repeat(self.last_msg.split(":")[1])),
"PLAYONLOAD": lambda: self._retMsg(self.set_play_on_load(int(self.last_msg.split(":")[1]))),
# Show Plan Items
"LOAD": lambda: self._retMsg(self.load(int(self.last_msg.split(":")[1]))),
"LOADED?": lambda: self._retMsg(self.isLoaded),
"UNLOAD": lambda: self._retMsg(self.unload()),
"STATUS": lambda: self._retMsg(self.status, True),
"ADD": lambda: self._retMsg(self.add_to_plan(json.loads(":".join(self.last_msg.split(":")[1:])))),
"REMOVE": lambda: self._retMsg(self.remove_from_plan(int(self.last_msg.split(":")[1]))),
"CLEAR": lambda: self._retMsg(self.clear_channel_plan())

View file

@ -141,6 +141,21 @@ def output(channel, name):
channel_to_q[channel].put("OUTPUT:" + name)
return ui_status()
@app.route("/player/<int:channel>/autoadvance/<int:state>")
def autoadvance(channel: int, state: int):
channel_to_q[channel].put("AUTOADVANCE:" + str(state))
return ui_status()
@app.route("/player/<int:channel>/repeat/<state>")
def autoadvance(channel: int, state):
channel_to_q[channel].put("REPEAT:" + state.upper())
return ui_status()
@app.route("/player/<int:channel>/playonload/<int:state>")
def autoadvance(channel: int, state: int):
channel_to_q[channel].put("PLAYONLOAD:" + str(state))
return ui_status()
### Channel Items
@app.route("/player/<int:channel>/load/<int:timeslotitemid>")