Struct sfml::audio::Sound[][src]

pub struct Sound<'s> { /* fields omitted */ }

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]

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]

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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.