Struct ears::Sound [] [src]

pub struct Sound {
    // some fields omitted
}

Play Sounds easily.

Simple class to play sounds easily in 2 lines. Sounds are really light objects, the sound's data is entirely loaded into memory and can be shared between Sounds using the SoundData object.

Examples

extern crate ears;
use ears::{Sound, AudioController};

fn main() -> () {
   // Create a Sound with the path of the sound file.
   let mut snd = Sound::new("path/to/my/sound.ogg").unwrap();

   // Play it
   snd.play();

   // Wait until the sound stopped playing
   while snd.is_playing() {}
}

Methods

impl Sound

fn new(path: &str) -> Option<Sound>

Default constructor for Sound struct.

Create a new struct and an associated SoundData.

Argument

path - The path of the sound file to create the SoundData.

Return

An Option with Some(Sound) if the Sound is created properly, or None if un error has occured.

Example

let snd = match ears::Sound::new("path/to/the/sound.ogg") {
    Some(snd) => snd,
    None      => panic!("Cannot load the sound from a file !")
};

fn new_with_data(sound_data: Rc<RefCell<SoundData>>) -> Option<Sound>

Create a new struct with a SoundData to associate.

Argument

sound_data - The sound_data to associate to the Sound.

Return

An Option with Some(Sound) if the Sound is created properly, or None if un error has occured.

Example

use ears::{Sound, SoundData, AudioController};
use std::rc::Rc;
use std::cell::RefCell;

let snd_data = match SoundData::new("path/to/the/sound.ogg") {
    Some(snd_data) => Rc::new(RefCell::new(snd_data)),
    None           => panic!("Cannot create the sound data !")
};
let mut snd = match Sound::new_with_data(snd_data) {
    Some(mut snd) => snd.play(),
    None      => panic!("Cannot create a sound using a sound data !")
};

fn get_datas(&self) -> Rc<RefCell<SoundData>>

Get the sound datas.

Return

The SoundData associated to this Sound.

Example

let snd = ears::Sound::new("path/to/the/sound.ogg").unwrap();
let snd_data = snd.get_datas();

fn set_datas(&mut self, sound_data: Rc<RefCell<SoundData>>)

Set the sound datas.

Doesn't work if the sound is currently playing.

Argument

sound_data - The new sound_data

Example

let snd1 = ears::Sound::new("path/to/the/sound.ogg").unwrap();
let mut snd2 = ears::Sound::new("other/path/to/the/sound.ogg").unwrap();
let snd_data = snd1.get_datas();
snd2.set_datas(snd_data);

Trait Implementations

impl AudioTags for Sound

fn get_tags(&self) -> Tags

impl AudioController for Sound

fn play(&mut self)

fn pause(&mut self)

fn stop(&mut self)

fn is_playing(&self) -> bool

fn get_state(&self) -> State

fn set_volume(&mut self, volume: f32)

fn get_volume(&self) -> f32

fn set_min_volume(&mut self, min_volume: f32)

fn get_min_volume(&self) -> f32

fn set_max_volume(&mut self, max_volume: f32)

fn get_max_volume(&self) -> f32

fn set_looping(&mut self, looping: bool)

fn is_looping(&self) -> bool

fn set_pitch(&mut self, pitch: f32)

fn get_pitch(&self) -> f32

fn set_relative(&mut self, relative: bool)

fn is_relative(&mut self) -> bool

fn set_position(&mut self, position: [f32; 3])

fn get_position(&self) -> [f32; 3]

fn set_direction(&mut self, direction: [f32; 3])

fn get_direction(&self) -> [f32; 3]

fn set_max_distance(&mut self, max_distance: f32)

fn get_max_distance(&self) -> f32

fn set_reference_distance(&mut self, ref_distance: f32)

fn get_reference_distance(&self) -> f32

fn set_attenuation(&mut self, attenuation: f32)

fn get_attenuation(&self) -> f32

impl Drop for Sound

fn drop(&mut self)