pub struct Audio {
pub channel: Sender<AudioCommand>,
}Expand description
Holds the command channel
Fields§
§channel: Sender<AudioCommand>Tokio mpsc sender used to communicate with the audio thread
Implementations§
Source§impl Audio
impl Audio
Sourcepub fn new() -> Audio
pub fn new() -> Audio
Creates a new Audio instance and spawns the background audio thread
Workflow:
- Opens a default
rodiooutput stream. - Listens on an mpsc channel for
AudioCommands. - On
Play, stops any existing sink and starts a new one.
Sourcepub async fn play_audio(
&mut self,
path: &Path,
_interrupt_current_playback: bool,
) -> Result<()>
pub async fn play_audio( &mut self, path: &Path, _interrupt_current_playback: bool, ) -> Result<()>
Sends a Play command for the given path
Examples found in repository?
examples/hello.rs (line 45)
29 fn key_down_event(
30 &self,
31 game: &mut Game,
32 _timestamp: u64,
33 _window_id: u32,
34 keycode: Option<sdl3::keyboard::Keycode>,
35 _scancode: Option<sdl3::keyboard::Scancode>,
36 _keymod: sdl3::keyboard::Mod,
37 _repeat: bool,
38 _which: u32,
39 _raw: u16,
40 ) -> anyhow::Result<()> {
41 println!("{:?}", keycode);
42 tokio::task::block_in_place(move || {
43 Handle::current().block_on(async move {
44 game.audio
45 .play_audio(Path::new("examples/music.ogg"), false)
46 .await
47 .unwrap();
48 })
49 });
50 Ok(())
51 }Trait Implementations§
Auto Trait Implementations§
impl Freeze for Audio
impl RefUnwindSafe for Audio
impl Send for Audio
impl Sync for Audio
impl Unpin for Audio
impl UnwindSafe for Audio
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian().