pub struct Player { /* private fields */ }Expand description
Handle to a device that outputs sounds.
Dropping the Player stops all its sounds. You can use detach if you want the sounds to continue
playing.
Implementations§
Source§impl Player
impl Player
Sourcepub fn connect_new(mixer: &Mixer) -> Player
pub fn connect_new(mixer: &Mixer) -> Player
Builds a new Player, beginning playback on a stream.
Sourcepub fn new() -> (Player, SourcesQueueOutput)
pub fn new() -> (Player, SourcesQueueOutput)
Builds a new Player.
Sourcepub fn volume(&self) -> Float
pub fn volume(&self) -> Float
Gets the volume of the sound.
The value 1.0 is the “normal” volume (unfiltered input). Any value other than 1.0 will
multiply each sample by this value.
Sourcepub fn set_volume(&self, value: Float)
pub fn set_volume(&self, value: Float)
Changes the volume of the sound.
The value 1.0 is the “normal” volume (unfiltered input). Any value other than 1.0 will
multiply each sample by this value.
Sourcepub fn speed(&self) -> f32
pub fn speed(&self) -> f32
Gets the speed of the sound.
See Player::set_speed for details on what speed means.
Sourcepub fn set_speed(&self, value: f32)
pub fn set_speed(&self, value: f32)
Changes the play speed of the sound. Does not adjust the samples, only the playback speed.
§Note:
- Increasing the speed will increase the pitch by the same factor
- If you set the speed to 0.5 this will halve the frequency of the sound lowering its pitch.
- If you set the speed to 2 the frequency will double raising the pitch of the sound.
- Change in the speed affect the total duration inversely
- If you set the speed to 0.5, the total duration will be twice as long.
- If you set the speed to 2 the total duration will be halve of what it was.
Sourcepub fn try_seek(&self, pos: Duration) -> Result<(), SeekError>
pub fn try_seek(&self, pos: Duration) -> Result<(), SeekError>
Attempts to seek to a given position in the current source.
This blocks between 0 and ~5 milliseconds.
As long as the duration of the source is known, seek is guaranteed to saturate
at the end of the source. For example given a source that reports a total duration
of 42 seconds calling try_seek() with 60 seconds as argument will seek to
42 seconds.
§Errors
This function will return SeekError::NotSupported if one of the underlying
sources does not support seeking.
It will return an error if an implementation ran into one during the seek.
When seeking beyond the end of a source this function might return an error if the duration of the source is not known.
Sourcepub fn pause(&self)
pub fn pause(&self)
Pauses playback of this player.
No effect if already paused.
A paused sink can be resumed with play().
Sourcepub fn is_paused(&self) -> bool
pub fn is_paused(&self) -> bool
Gets if a sink is paused
Players can be paused and resumed using pause() and play(). This returns true if the
sink is paused.
Sourcepub fn clear(&self)
pub fn clear(&self)
Removes all currently loaded Sources from the Player, and pauses it.
See pause() for information about pausing a Player.
Sourcepub fn skip_one(&self)
pub fn skip_one(&self)
Skips to the next Source in the Player
If there are more Sources appended to the Player at the time,
it will play the next one. Otherwise, the Player will finish as if
it had finished playing a Source all the way through.
Sourcepub fn sleep_until_end(&self)
pub fn sleep_until_end(&self)
Sleeps the current thread until the sound ends.