Struct sfml::audio::Sound [−][src]
Regular sound that can be played in the audio environment.
Sound
is the type to use to play sounds.
It provides:
- Control (play, pause, stop)
- Ability to modify output parameters in real-time (pitch, volume, …)
- 3D spatial features (position, attenuation, …).
Sound
is perfect for playing short sounds that can fit in memory and require no latency,
like foot steps or gun shots. For longer sounds, like background musics or long speeches,
rather see Music
(which is based on streaming).
In order to work, a sound must be given a buffer of audio data to play.
Audio data (samples) is stored in SoundBuffer
, and attached to a sound with the
set_buffer
function. The buffer object attached to a sound must remain alive as long as
the sound uses it. Note that multiple sounds can use the same sound buffer at the same time.
Usage example
use sfml::audio::{Sound, SoundBuffer}; let buffer = SoundBuffer::from_file("sound.wav").unwrap(); let mut sound = Sound::with_buffer(&buffer); sound.play();
Implementations
impl<'s> Sound<'s>
[src]
#[must_use]pub fn new() -> Sound<'s>
[src]
Create a new Sound
#[must_use]pub fn with_buffer(buffer: &SoundBuffer) -> Sound<'_>
[src]
Create a new Sound
with a buffer
pub fn set_looping(&mut self, looping: bool)
[src]
Sets whether this sound should loop or not.
#[must_use]pub fn is_looping(&self) -> bool
[src]
Tell whether or not a sound is in loop mode
Return true if the sound is looping, false otherwise
pub fn play(&mut self)
[src]
Start or resume playing a sound
This function starts the sound if it was stopped, resumes it if it was paused, and restarts it from beginning if it was it already playing. This function uses its own thread so that it doesn’t block the rest of the program while the sound is played.
pub fn pause(&mut self)
[src]
Pause a sound
This function pauses the sound if it was playing, otherwise (sound already paused or stopped) it has no effect.
pub fn stop(&mut self)
[src]
Stop playing a sound
This function stops the sound if it was playing or paused, and does nothing if it was already stopped. It also resets the playing position (unlike pause).
#[must_use]pub fn status(&self) -> SoundStatus
[src]
Get the current status of a sound (stopped, paused, playing)
Return current status
#[must_use]pub fn playing_offset(&self) -> Time
[src]
Get the current playing position of a sound
Return the current playing position
pub fn set_playing_offset(&mut self, time_offset: Time)
[src]
Change the current playing position of a sound
The playing position can be changed when the sound is either paused or playing.
Arguments
- timeOffset - New playing position
pub fn set_buffer(&mut self, buffer: &'s SoundBuffer)
[src]
Set the source buffer containing the audio data to play
Arguments
- buffer - Sound buffer to attach to the sound
#[must_use]pub fn buffer(&self) -> Option<&SoundBuffer>
[src]
Get the audio buffer attached to a sound
Return an option to Sound buffer attached to the sound or None
Trait Implementations
impl<'s> Clone for Sound<'s>
[src]
fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<'s> Debug for Sound<'s>
[src]
impl<'a> Default for Sound<'a>
[src]
impl<'s> Drop for Sound<'s>
[src]
impl<'s> SoundSource for Sound<'s>
[src]
fn set_pitch(&mut self, pitch: f32)
[src]
fn set_volume(&mut self, volume: f32)
[src]
fn set_position<P: Into<Vector3f>>(&mut self, position: P)
[src]
fn set_relative_to_listener(&mut self, relative: bool)
[src]
fn set_min_distance(&mut self, distance: f32)
[src]
fn set_attenuation(&mut self, attenuation: f32)
[src]
fn pitch(&self) -> f32
[src]
fn volume(&self) -> f32
[src]
fn position(&self) -> Vector3f
[src]
fn is_relative_to_listener(&self) -> bool
[src]
fn min_distance(&self) -> f32
[src]
fn attenuation(&self) -> f32
[src]
Auto Trait Implementations
impl<'s> RefUnwindSafe for Sound<'s>
impl<'s> !Send for Sound<'s>
impl<'s> !Sync for Sound<'s>
impl<'s> Unpin for Sound<'s>
impl<'s> UnwindSafe for Sound<'s>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,