pub trait AudioControl {
    // Required methods
    fn play(&self, audio_source: Handle<AudioSource>) -> PlayAudioCommand<'_>;
    fn stop(&self) -> TweenCommand<'_, FadeOut>;
    fn pause(&self) -> TweenCommand<'_, FadeOut>;
    fn resume(&self) -> TweenCommand<'_, FadeIn>;
    fn set_volume(&self, volume: impl Into<Volume>) -> TweenCommand<'_, FadeIn>;
    fn set_panning(&self, panning: f64) -> TweenCommand<'_, FadeIn>;
    fn set_playback_rate(&self, playback_rate: f64) -> TweenCommand<'_, FadeIn>;
    fn state(&self, instance_handle: &Handle<AudioInstance>) -> PlaybackState;
    fn is_playing_sound(&self) -> bool;
}
Expand description

Play and control audio

Required Methods§

source

fn play(&self, audio_source: Handle<AudioSource>) -> PlayAudioCommand<'_>

Play audio


fn my_system(asset_server: Res<AssetServer>, audio: Res<Audio>) {
    audio.play(asset_server.load("audio.mp3"));
}
source

fn stop(&self) -> TweenCommand<'_, FadeOut>

Stop all audio


fn my_system(audio: Res<Audio>) {
    audio.stop();
}
source

fn pause(&self) -> TweenCommand<'_, FadeOut>

Pause all audio


fn my_system(audio: Res<Audio>) {
    audio.pause();
}
source

fn resume(&self) -> TweenCommand<'_, FadeIn>

Resume all audio


fn my_system(audio: Res<Audio>) {
    audio.resume();
}
source

fn set_volume(&self, volume: impl Into<Volume>) -> TweenCommand<'_, FadeIn>

Set the volume

The default value is 1. This method supports setting the volume in Decibels or as Amplitude.


fn my_system(audio: Res<Audio>) {
    audio.set_volume(0.5);
}
source

fn set_panning(&self, panning: f64) -> TweenCommand<'_, FadeIn>

Set panning

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);
}
source

fn set_playback_rate(&self, playback_rate: f64) -> TweenCommand<'_, FadeIn>

Set playback rate

The default value is 1


fn my_system(audio: Res<Audio>) {
    audio.set_playback_rate(2.0);
}
source

fn state(&self, instance_handle: &Handle<AudioInstance>) -> PlaybackState

Get state for a playback instance.

source

fn is_playing_sound(&self) -> bool

Returns true if there is any sound in this channel that is in the state Playing, Pausing, or Stopping

If there are only Stopped, Paused, or Queued sounds, the method will return false. The same result is returned if there are no sounds in the channel at all.

Object Safety§

This trait is not object safe.

Implementors§