pub struct AudioManager { /* private fields */ }Expand description
This struct manages audio playback.
It allows playing multiple songs simultaneously, stopping them individually or all at once, and adjusting their volumes
It handles everything in a dedicated audio thread to ensure smooth playback and to not disrupt any other tasks.
§Usage:
use rs_audio::*;
let mut audio_manager = AudioManager::new();
let song = Song::default();
let track_id = audio_manager.play(song); // play the song and get its track ID
audio_manager.set_volume(track_id, 0.5); // set volume for this track
audio_manager.stop(track_id); // stop this specific track
audio_manager.stop_all(); // stop all tracksImplementations§
Source§impl AudioManager
impl AudioManager
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new AudioManager instance and starts the audio thread.
This thread handles all audio playback and control.
It uses channels to receive commands from the main thread.
§Usage:
use rs_audio::*;
let mut audio_manager = AudioManager::new();Sourcepub fn play(&mut self, song: Song) -> usize
pub fn play(&mut self, song: Song) -> usize
Plays a song and returns a unique track ID for later control (like stopping or adjusting volume).
Sourcepub fn set_volume(&self, track_id: usize, volume: f32)
pub fn set_volume(&self, track_id: usize, volume: f32)
Sets the volume for a specific track using its track ID.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AudioManager
impl RefUnwindSafe for AudioManager
impl Send for AudioManager
impl Sync for AudioManager
impl Unpin for AudioManager
impl UnwindSafe for AudioManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more