implement trivial volume control slider and reporting of current volume to webinterface
This commit is contained in:
		
				
					committed by
					
						
						Terry Geng
					
				
			
			
				
	
			
			
			
						parent
						
							2d788c77f5
						
					
				
				
					commit
					f95e07c9af
				
			
							
								
								
									
										16
									
								
								interface.py
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								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()
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -72,6 +72,11 @@
 | 
			
		||||
                                    onclick="request('post', {action : 'volume_up'})">
 | 
			
		||||
                                <i class="fa fa-volume-up" aria-hidden="true"></i>
 | 
			
		||||
                            </button>
 | 
			
		||||
 | 
			
		||||
                            <input id="volume-slider" type="range"
 | 
			
		||||
                                    min="0" max="100" step="1" value="50"
 | 
			
		||||
                                    onchange="request('post', {action : 'volume_set_value', new_volume : this.value})">
 | 
			
		||||
                            </input>
 | 
			
		||||
                        </div>
 | 
			
		||||
 | 
			
		||||
                        <table class="table">
 | 
			
		||||
@@ -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(){
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user