Struct bevy_kira_audio::Audio [−][src]
pub struct Audio { /* fields omitted */ }
Expand description
Bevy Audio Resource
Use this resource to play and control your audio
fn start_audio_system(asset_server: Res<AssetServer>, audio: Res<Audio>) { audio.play(asset_server.load("audio.mp3")); }
Implementations
Play audio in the default channel
fn my_system(asset_server: Res<AssetServer>, audio: Res<Audio>) { audio.play(asset_server.load("audio.mp3")); }
Play looped audio in the default channel
fn my_system(asset_server: Res<AssetServer>, audio: Res<Audio>) { audio.play_looped(asset_server.load("audio.mp3")); }
Stop all audio in the default channel
fn my_system(audio: Res<Audio>) { audio.stop(); }
Pause all audio in the default channel
fn my_system(audio: Res<Audio>) { audio.pause(); }
Resume all audio in the default channel
fn my_system(audio: Res<Audio>) { audio.resume(); }
Set the volume for the default channel
The default value is 1
fn my_system(audio: Res<Audio>) { audio.set_volume(0.5); }
Set panning for the default channel
The default value is 0.5 Values up to 1 pan to the right Values down to 0 pan to the left
fn my_system(audio: Res<Audio>) { audio.set_panning(0.9); }
Set playback rate for the default channel
The default value is 1
fn my_system(audio: Res<Audio>) { audio.set_playback_rate(2.0); }
Play audio in the given channel
fn my_system(asset_server: Res<AssetServer>, audio: Res<Audio>) { audio.play_in_channel(asset_server.load("audio.mp3"), &AudioChannel::new("my-channel".to_owned())); }
pub fn play_looped_in_channel(
&self,
audio_source: Handle<AudioSource>,
channel_id: &AudioChannel
)
pub fn play_looped_in_channel(
&self,
audio_source: Handle<AudioSource>,
channel_id: &AudioChannel
)
Play looped audio in the given channel
fn my_system(asset_server: Res<AssetServer>, audio: Res<Audio>) { audio.play_looped_in_channel(asset_server.load("audio.mp3"), &AudioChannel::new("my-channel".to_owned())); }
Stop audio in the given channel
fn my_system(audio: Res<Audio>) { audio.stop_channel(&AudioChannel::new("my-channel".to_owned())); }
Pause audio in the given channel
fn my_system(audio: Res<Audio>) { audio.pause_channel(&AudioChannel::new("my-channel".to_owned())); }
Resume audio in the given channel
fn my_system(audio: Res<Audio>) { audio.resume_channel(&AudioChannel::new("my-channel".to_owned())); }
Set the volume for the given channel
The default value is 1
fn my_system(audio: Res<Audio>) { audio.set_volume_in_channel(0.5, &AudioChannel::new("my-channel".to_owned())); }
Set panning for the given channel
The default value is 0.5 Values up to 1 pan to the right Values down to 0 pan to the left
fn my_system(audio: Res<Audio>) { audio.set_panning_in_channel(0.9, &AudioChannel::new("my-channel".to_owned())); }
Set playback rate for the given channel
The default value is 1
fn my_system(audio: Res<Audio>) { audio.set_playback_rate_in_channel(2.0, &AudioChannel::new("my-channel".to_owned())); }
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Audio
impl UnwindSafe for Audio
Blanket Implementations
Mutably borrows from an owned value. Read more
impl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
Convert Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read more
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert &mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more
impl<T> FromWorld for T where
T: Default,
impl<T> FromWorld for T where
T: Default,
pub fn from_world(_world: &mut World) -> T
pub fn from_world(_world: &mut World) -> T
Creates Self
using data from the given [World]
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
pub fn vzip(self) -> V