def stop(self): if not self._playing: return if self.can_pause and self._playing: check(asound.snd_pcm_pause(self.pcm, 1)) self._stop_alsatime = self._get_asound_time() else: # Hardware can't pause, so we'll just drop everything that's # been buffered. Improvement could be to rebuffer data that # wasn't played. self.clear() self._playing = False
def play(self): if self._playing: return self._playing = True if not self._sources: return if self._device: state = asound.snd_pcm_state(self._device.pcm) if self._device.can_pause and state == asound.SND_PCM_STATE_PAUSED: check(asound.snd_pcm_pause(self._device.pcm, 0)) self._set_start_time(self._sources[0], self._timestamp)
def play(self): if self._playing: return state = asound.snd_pcm_state(self.pcm) if self.can_pause and state == asound.SND_PCM_STATE_PAUSED: check(asound.snd_pcm_pause(self.pcm, 0)) elif state not in (asound.SND_PCM_STATE_RUNNING, asound.SND_PCM_STATE_PREPARED): check(asound.snd_pcm_prepare(self.pcm)) self._playing = True if self._stop_alsatime is not None: diff = self._get_asound_time() - self._stop_alsatime self._timestamps = [(a + diff, t) for a, t in self._timestamps] self._stop_alsatime = None
def pause(self): if not self._playing: return self._playing = False if not self._sources: return if self._device: self._timestamp = self._get_asound_time() - self._start_time if self._device.can_pause: check(asound.snd_pcm_pause(self._device.pcm, 1)) else: # Hardware can't pause, so we'll just drop everything that's # been buffered. Improvement could be to rebuffer data that # wasn't played. self._clear_ring_buffer()