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

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

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

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

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

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

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait. Read more

Performs the conversion.

Creates Self using data from the given [World]

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.