From f95e07c9af11ce813f6beefe76422c07a4cf0dfe Mon Sep 17 00:00:00 2001 From: Daniel Gunzinger Date: Thu, 16 Apr 2020 19:09:24 +0200 Subject: [PATCH] implement trivial volume control slider and reporting of current volume to webinterface --- interface.py | 16 ++++++++++++++-- templates/index.html | 13 +++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/interface.py b/interface.py index fd8c794..9e8c5bb 100644 --- a/interface.py +++ b/interface.py @@ -234,13 +234,15 @@ def status(): 'current_index': var.playlist.current_index, 'empty': False, 'play': not var.bot.is_pause, - 'mode': var.playlist.mode}) + 'mode': var.playlist.mode, + 'volume': var.db.getfloat('bot', 'volume')}) else: return jsonify({'ver': var.playlist.version, 'current_index': var.playlist.current_index, 'empty': True, 'play': not var.bot.is_pause, - 'mode': var.playlist.mode}) + 'mode': var.playlist.mode, + 'volume': var.db.getfloat('bot', 'volume')}) @web.route("/post", methods=['POST']) @@ -401,6 +403,16 @@ def post(): var.bot.volume_set = 0 var.db.set('bot', 'volume', str(var.bot.volume_set)) log.info("web: volume up to %d" % (var.bot.volume_set * 100)) + elif action == "volume_set_value": + if 'new_volume' in request.form: + # new_volume is slider value ranging from 0-100 + var.bot.volume_set = (request.form['new_volume'] * 0.01) + if var.bot.volume_set > 1: + var.bot.volume_set = 1 + elif var.bot.volume_set < 0: + var.bot.volume_set = 0 + var.db.set('bot', 'volume', str(var.bot.volume_set)) + log.info("web: volume set to %d" % (var.bot.volume_set * 100)) return status() diff --git a/templates/index.html b/templates/index.html index 17cc72d..164a488 100644 --- a/templates/index.html +++ b/templates/index.html @@ -72,6 +72,11 @@ onclick="request('post', {action : 'volume_up'})"> + + + @@ -497,7 +502,7 @@ if (data.ver !== playlist_ver) { checkForPlaylistUpdate(); } - updateControls(data.empty, data.play, data.mode); + updateControls(data.empty, data.play, data.mode, data.volume); } } }); @@ -659,7 +664,7 @@ displayActiveItem(data.current_index); } } - updateControls(data.empty, data.play, data.mode); + updateControls(data.empty, data.play, data.mode, data.volume); } } }); @@ -682,7 +687,7 @@ ); } - function updateControls(empty, play, mode){ + function updateControls(empty, play, mode, volume){ if(empty){ $("#play-btn").prop("disabled", true); $("#pause-btn").prop("disabled", true); @@ -719,7 +724,7 @@ $("#random-btn").removeClass("btn-primary").addClass("btn-secondary").prop("disabled", false); $("#autoplay-btn").removeClass("btn-secondary").addClass("btn-primary").prop("disabled", true); } - + $("#volume-slider").value = volume; } function themeInit(){