change where we get the current volume from in the status method; adjust html input range from 0-100 to 0-1, thus remove need for scaling in javascript

This commit is contained in:
Daniel Gunzinger 2020-04-17 17:12:26 +02:00
parent b9fd17677b
commit 788383f65c
2 changed files with 15 additions and 8 deletions

View File

@ -235,14 +235,14 @@ def status():
'empty': False,
'play': not var.bot.is_pause,
'mode': var.playlist.mode,
'volume': var.db.getfloat('bot', 'volume')})
'volume': var.bot.volume_set})
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,
'volume': var.db.getfloat('bot', 'volume')})
'volume': var.bot.volume_set})
@web.route("/post", methods=['POST'])
@ -405,12 +405,13 @@ def post():
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 = (int(request.form['new_volume']) * 0.01)
if var.bot.volume_set > 1:
if float(request.form['new_volume']) > 1:
var.bot.volume_set = 1
elif var.bot.volume_set < 0:
elif float(request.form['new_volume']) < 0:
var.bot.volume_set = 0
else:
# value for new volume is between 0 and 1, round to two decimal digits
var.bot.volume_set = round(float(request.form['new_volume']), 2)
var.db.set('bot', 'volume', str(var.bot.volume_set))
log.info("web: volume set to %d" % (var.bot.volume_set * 100))

View File

@ -70,7 +70,7 @@
</button>
<input type="range" class="custom-range" id="volume-slider"
min="0" max="100" step="1" value="50"
min="0" max="1" step="0.01" value="0.5"
onchange="request('post', {action : 'volume_set_value', new_volume : this.value})">
</input>
@ -726,7 +726,13 @@
$("#random-btn").removeClass("btn-primary").addClass("btn-secondary").prop("disabled", false);
$("#autoplay-btn").removeClass("btn-secondary").addClass("btn-primary").prop("disabled", true);
}
document.getElementById("volume-slider").value = Math.round(volume*100);
if(volume > 1) {
document.getElementById("volume-slider").value = 1;
} else if(volume < 0) {
document.getElementById("volume-slider").value = 0;
} else {
document.getElementById("volume-slider").value = volume;
}
}
function themeInit(){