rest - Python Flask persistent object between requests -
i creating web interface omxplayer on raspberry pi. i'm trying create more rest api controlling video while playing. issue i'm having how control video while playing.
currently can create player object methods available start , stop video.
@main.route("/video", methods=["get", "post"]) @login_required def video(): form = videoform() if form.validate_on_submit(): url = form.url.data vid_output = form.vid_output.data player = player(url=url, output=vid_output) player.toggle_pause() return redirect('/video') return render_template("video.html", form=form)
now want have url can run player.toggle_pause() method again.
@main.route("/video/stop", methods=["get", "post"]) @login_required def video_stop(): player.toggle_pause()
my problem cannot find way have object persist between 2 requests. video start playing after sending first request, trying stop or control not allow me access created object. there way persist object between 2 seperate requests?
the way preserve information across requests store somewhere , retrieve on next request. or recreate object (including state) using parameters passed client.
for case, since you'll using 1 player
@ given time, can make global. (stripped lines consiseness)
player = none def video(): global player form = videoform() if form.validate_on_submit(): url = form.url.data vid_output = form.vid_output.data player = player(url=url, output=vid_output) def video_pause(): global player if not player: return player.toggle_pause() def video_stop(): global player if not player: return player.exit_omx_player() player = none
Comments
Post a Comment