implement trivial volume control slider and reporting of current volume to webinterface

This commit is contained in:
Daniel Gunzinger
2020-04-16 19:09:24 +02:00
committed by Terry Geng
parent 2d788c77f5
commit f95e07c9af
2 changed files with 23 additions and 6 deletions

View File

@ -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()