Struct ears::SoundData [] [src]

pub struct SoundData {
    // some fields omitted
}

Samples extracted from a file.

SoundDatas are made to be shared between several Sound and played in the same time.

Example

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

fn main() -> () {
  // Create a SoundData
  let snd_data = Rc::new(RefCell::new(SoundData::new("path/to/my/sound.wav")
                                      .unwrap()));

  // Create two Sound with the same SoundData
  let mut snd1 = Sound::new_with_data(snd_data.clone()).unwrap();
  let mut snd2 = Sound::new_with_data(snd_data.clone()).unwrap();

  // Play the sounds
  snd1.play();
  snd2.play();

  // Wait until snd2 is playing
  while snd2.is_playing() {}
}

Methods

impl SoundData

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

Create a new SoundData.

The SoundData contains all the information extracted from the file: samples and tags. It's an easy way to share the same samples between man Sounds objects.

Arguments

  • path - The path of the file to load

Return

An Option with Some(SoundData) if the SoundData is create, or None if an error has occured.

Trait Implementations

impl AudioTags for SoundData

fn get_tags(&self) -> Tags

impl Drop for SoundData

fn drop(&mut self)