2
0
Fork 0
mirror of https://github.com/bevyengine/bevy synced 2024-12-29 06:23:09 +00:00
bevy/examples/audio/audio.rs
Carter Anderson 013e11a14f
AudioPlayer::new() ()
# Objective

`AudioPlayer::<AudioSource>(assets.load("audio.mp3"))` is awkward and
complicated to type because the `AudioSource` generic type cannot be
elided. This is especially annoying because `AudioSource` is used in the
majority of cases. Most users don't need to think about it.

## Solution

Add an `AudioPlayer::new()` function that is hard-coded to
`AudioSource`, allowing `AudioPlayer::new(assets.load("audio.mp3"))`.
Prefer using that in the relevant places.
2024-11-08 01:51:50 +00:00

17 lines
486 B
Rust

//! This example illustrates how to load and play an audio file.
//! For loading additional audio formats, you can enable the corresponding feature for that audio format.
use bevy::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.run();
}
fn setup(asset_server: Res<AssetServer>, mut commands: Commands) {
commands.spawn(AudioPlayer::new(
asset_server.load("sounds/Windless Slopes.ogg"),
));
}