def set_volume(self, volume): """ Set volume level of the installed mixer. :param volume: the volume in the range [0..100] :type volume: int :rtype: :class:`True` if successful, else :class:`False` """ if self._software_mixing: self._playbin.set_property('volume', volume / 100.0) return True if self._mixer is None: return False old_scale = (0, 100) new_scale = (self._mixer_track.min_volume, self._mixer_track.max_volume) volume = utils.rescale(volume, old=old_scale, new=new_scale) volumes = (volume, ) * self._mixer_track.num_channels self._mixer.set_volume(self._mixer_track, volumes) return self._mixer.get_volume(self._mixer_track) == volumes
def get_volume(self): """ Get volume level of the installed mixer. Example values: 0: Muted. 100: Max volume for given system. :class:`None`: No mixer present, so the volume is unknown. :rtype: int in range [0..100] or :class:`None` """ if self._software_mixing: return round(self._playbin.get_property('volume') * 100) if self._mixer is None: return None volumes = self._mixer.get_volume(self._mixer_track) avg_volume = float(sum(volumes)) / len(volumes) new_scale = (0, 100) old_scale = (self._mixer_track.min_volume, self._mixer_track.max_volume) return utils.rescale(avg_volume, old=old_scale, new=new_scale)
def set_volume(self, volume): """ Set volume level of the installed mixer. :param volume: the volume in the range [0..100] :type volume: int :rtype: :class:`True` if successful, else :class:`False` """ if self._software_mixing: self._playbin.set_property('volume', volume / 100.0) return True if self._mixer is None: return False old_scale = (0, 100) new_scale = (self._mixer_track.min_volume, self._mixer_track.max_volume) volume = utils.rescale(volume, old=old_scale, new=new_scale) volumes = (volume,) * self._mixer_track.num_channels self._mixer.set_volume(self._mixer_track, volumes) return self._mixer.get_volume(self._mixer_track) == volumes