Mute the channel when setting the volume to minimum.
This commit is contained in:
parent
42385b069f
commit
d3e8ddb278
@ -46,20 +46,28 @@ class HardwareManager(object):
|
|||||||
|
|
||||||
for track in self._mixer.list_tracks():
|
for track in self._mixer.list_tracks():
|
||||||
if track.flags & gst.interfaces.MIXER_TRACK_MASTER:
|
if track.flags & gst.interfaces.MIXER_TRACK_MASTER:
|
||||||
self._mixer_master = track
|
self._master = track
|
||||||
|
|
||||||
def set_volume(self, volume):
|
def set_volume(self, volume):
|
||||||
|
if not self._mixer or not self._master:
|
||||||
|
logging.error('Cannot set the volume')
|
||||||
|
|
||||||
if volume < 0 or volume > 100:
|
if volume < 0 or volume > 100:
|
||||||
logging.error('Trying to set an invalid volume value.')
|
logging.error('Trying to set an invalid volume value.')
|
||||||
return
|
return
|
||||||
|
|
||||||
max_volume = self._mixer_master.max_volume
|
max_volume = self._master.max_volume
|
||||||
min_volume = self._mixer_master.min_volume
|
min_volume = self._master.min_volume
|
||||||
|
|
||||||
volume = (volume / 100.0) * (max_volume - min_volume) + min_volume
|
volume = (volume / 100.0) * (max_volume - min_volume) + min_volume
|
||||||
volume_list = [ volume ] * self._mixer_master.num_channels
|
volume_list = [ volume ] * self._master.num_channels
|
||||||
|
|
||||||
self._mixer.set_volume(self._mixer_master, tuple(volume_list))
|
self._mixer.set_volume(self._master, tuple(volume_list))
|
||||||
|
|
||||||
|
def set_mute(self, mute):
|
||||||
|
if not self._mixer or not self._master:
|
||||||
|
logging.error('Cannot mute the audio channel')
|
||||||
|
self._mixer.set_mute(self._master, mute)
|
||||||
|
|
||||||
def set_display_mode(self, mode):
|
def set_display_mode(self, mode):
|
||||||
if not self._service:
|
if not self._service:
|
||||||
|
@ -99,18 +99,21 @@ class KeyHandler(object):
|
|||||||
|
|
||||||
def handle_volume_1(self):
|
def handle_volume_1(self):
|
||||||
hw_manager = hardwaremanager.get_hardware_manager()
|
hw_manager = hardwaremanager.get_hardware_manager()
|
||||||
hw_manager.set_volume(0)
|
hw_manager.set_mute(True)
|
||||||
|
|
||||||
def handle_volume_2(self):
|
def handle_volume_2(self):
|
||||||
hw_manager = hardwaremanager.get_hardware_manager()
|
hw_manager = hardwaremanager.get_hardware_manager()
|
||||||
|
hw_manager.set_mute(False)
|
||||||
hw_manager.set_volume(50)
|
hw_manager.set_volume(50)
|
||||||
|
|
||||||
def handle_volume_3(self):
|
def handle_volume_3(self):
|
||||||
hw_manager = hardwaremanager.get_hardware_manager()
|
hw_manager = hardwaremanager.get_hardware_manager()
|
||||||
|
hw_manager.set_mute(False)
|
||||||
hw_manager.set_volume(80)
|
hw_manager.set_volume(80)
|
||||||
|
|
||||||
def handle_volume_4(self):
|
def handle_volume_4(self):
|
||||||
hw_manager = hardwaremanager.get_hardware_manager()
|
hw_manager = hardwaremanager.get_hardware_manager()
|
||||||
|
hw_manager.set_mute(False)
|
||||||
hw_manager.set_volume(100)
|
hw_manager.set_volume(100)
|
||||||
|
|
||||||
def handle_color_mode(self):
|
def handle_color_mode(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user