Skip to main content

AudioManager

Struct AudioManager 

Source
pub struct AudioManager { /* private fields */ }
Expand description

The audio manager controls playback, volume, and spatial audio.

§Example

let mut audio = AudioManager::new();
audio.load("jump", "sounds/jump.ogg");
audio.load("bgm", "music/theme.ogg");

// Play a sound effect
audio.play("jump");

// Play music with fade-in
audio.play_music("bgm", Fade::In(2.0));

// Update spatial audio
audio.update_listener_position(listener_pos);
audio.update(dt);

Implementations§

Source§

impl AudioManager

Source

pub fn new() -> Self

Create a new audio manager.

Source

pub fn load(&mut self, name: &str, _path: &str) -> Result<(), String>

Register a sound (in a real impl, this loads the audio file).

Source

pub fn load_with_config(&mut self, sound: Sound)

Register a sound with custom configuration.

Source

pub fn play(&mut self, name: &str)

Play a sound effect.

Source

pub fn play_on_channel(&mut self, name: &str, channel: AudioChannel)

Play a sound on a specific channel.

Source

pub fn play_music(&mut self, name: &str, fade: Fade)

Play music with optional fade.

Source

pub fn stop(&mut self, name: &str)

Stop all instances of a named sound.

Source

pub fn stop_channel(&mut self, channel: AudioChannel)

Stop all instances on a channel.

Source

pub fn stop_all(&mut self)

Stop all sounds.

Source

pub fn set_master_volume(&mut self, volume: f32)

Set the master volume (0.0–1.0).

Source

pub fn set_channel_volume(&mut self, channel: AudioChannel, volume: f32)

Set a channel’s volume (0.0–1.0).

Source

pub fn set_listener_position(&mut self, pos: Vec2)

Set the listener position for spatial audio.

Source

pub fn pause_all(&mut self)

Pause all audio.

Source

pub fn resume_all(&mut self)

Resume all audio.

Source

pub fn is_playing(&self, name: &str) -> bool

Check if a named sound is currently playing.

Source

pub fn update(&mut self, dt: f32)

Update the audio system (call once per frame).

Source

pub fn playing_count(&self) -> usize

Number of currently playing instances.

Trait Implementations§

Source§

impl Default for AudioManager

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.