--- name: bevy-audio-systems description: "Bevy ECS skill for audio playback. Keywords: Bevy, AudioPlayer, AudioSink, PlaybackSettings, AssetServer." --- # Bevy audio systems ## When to use Load this when a clip should start, loop, pause, or change volume. `bevy::audio` in Bevy 0.20 and the `audio_control` example are the sources. ## ECS shape - **Play:** spawn `AudioPlayer::new(asset_server.load(...))`. `AudioPlayer` holds `Handle` where `Source: Asset + Decodable`. If the asset is not ready, playback starts when it is. `AudioPlayer` requires `PlaybackSettings`. - **Settings:** `PlaybackSettings` configures the start. `PlaybackSettings::LOOP` and `.with_spatial(true)` appear in the spatial examples. Changes to `PlaybackSettings` do not affect audio that is already playing. `PlaybackMode` is `Once`, `Loop`, `Despawn`, or `Remove`. - **Control:** when playback begins, Bevy inserts `AudioSink`. The control example queries `AudioSink` and calls `pause`, `toggle_mute`, `set_volume`, `set_speed`, and `position`. `SpatialAudioSink` is the spatial counterpart named on the playback page. - **Replay:** after a non-looping sound finishes and the sink is drained, that `AudioPlayer` cannot be reused. Remove the audio components and add them again. - **Schedule:** spawn on `Startup` or from a system that has `Res` and `Commands`. Control systems in the example run where they read `ButtonInput` and `Res