def _handle_play_command(self, target: Optional[str]) -> None: if target is None: if self._current_playlist is not None and self._volume > 0: try: assert self._orig_volume is not None _ba.mac_music_app_stop() _ba.mac_music_app_set_volume(self._orig_volume) except Exception as exc: print('Error stopping iTunes music:', exc) self._current_playlist = None else: # If we've got something playing with positive # volume, stop it. if self._current_playlist is not None and self._volume > 0: try: assert self._orig_volume is not None _ba.mac_music_app_stop() _ba.mac_music_app_set_volume(self._orig_volume) except Exception as exc: print('Error stopping iTunes music:', exc) # Set our playlist and play it if our volume is up. self._current_playlist = target if self._volume > 0: self._orig_volume = (_ba.mac_music_app_get_volume()) self._update_mac_music_app_volume() self._play_current_playlist()
def set_volume(self, volume: float) -> None: """Set volume to a value between 0 and 1.""" old_volume = self._volume self._volume = volume # If we've got nothing we're supposed to be playing, # don't touch itunes/music. if self._current_playlist is None: return # If volume is going to zero, stop actually playing # but don't clear playlist. if old_volume > 0.0 and volume == 0.0: try: assert self._orig_volume is not None _ba.mac_music_app_stop() _ba.mac_music_app_set_volume(self._orig_volume) except Exception as exc: print('Error stopping iTunes music:', exc) elif self._volume > 0: # If volume was zero, store pre-playing volume and start # playing. if old_volume == 0.0: self._orig_volume = _ba.mac_music_app_get_volume() self._update_mac_music_app_volume() if old_volume == 0.0: self._play_current_playlist()
def _handle_die_command(self) -> None: # Only stop if we've actually played something # (we don't want to kill music the user has playing). if self._current_playlist is not None and self._volume > 0: try: assert self._orig_volume is not None _ba.mac_music_app_stop() _ba.mac_music_app_set_volume(self._orig_volume) except Exception as exc: print('Error stopping iTunes music:', exc)