Merge pull request #5 from tomaka/add-play-pause

Add play() and pause() functions
This commit is contained in:
tomaka 2014-12-23 15:28:43 +01:00
commit 73cd809636
5 changed files with 88 additions and 30 deletions

View file

@ -27,8 +27,15 @@ for e in buffer.iter_mut() {
This is the case if the device doesn't have enough space available. **It happens very often**,
this is not some obscure situation that can be ignored.
After you have submitted data for the first time, call `play`:
```no_run
# let mut voice = cpal::Voice::new();
voice.play();
```
The audio device of the user will read the buffer that you sent, and play it. If the audio device
reaches the end of the data, it will stop playing. You **must** continuously fill the buffer by
reaches the end of the data, it will stop playing. You must continuously fill the buffer by
calling `append_data` repeatedly if you don't want the audio to stop playing.
# Native format
@ -212,6 +219,25 @@ impl Voice {
}
}
}
/// Sends a command to the audio device that it should start playing.
///
/// Has no effect is the voice was already playing.
///
/// Only call this after you have submitted some data, otherwise you may hear
/// some glitches.
pub fn play(&mut self) {
self.0.play()
}
/// Sends a command to the audio device that it should stop playing.
///
/// Has no effect is the voice was already paused.
///
/// If you call `play` afterwards, the playback will resume exactly where it was.
pub fn pause(&mut self) {
self.0.pause()
}
}
impl<'a, T> Deref<[T]> for Buffer<'a, T> {