bevyengine/bevy
bevy_audio
Audio playback. Wraps rodio with a Bevy-native API: load a sound as an asset, attach an AudioPlayer component, set volume/pitch/spatialization, despawn the entity to stop.
Purpose
bevy_audio provides:
- An
AudioSourceasset and per-format loaders (WAV, OGG/Vorbis, MP3, FLAC, AAC, and more, depending on cargo features). - A
Decodabletrait for plugging in custom decoders. - The
AudioPlayercomponent plus settings (PlaybackSettings). - 3D spatial audio with HRTF.
Directory layout
crates/bevy_audio/src/
├── lib.rs # AudioPlugin
├── audio_source.rs # AudioSource asset + loaders
├── audio.rs # AudioPlayer component
├── audio_output.rs # Output sink + system glue
├── pitch.rs # Pitch resource
├── sinks.rs # SpatialAudioSink, AudioSink
└── …Key abstractions
| Type | File | Description |
|---|---|---|
AudioPlugin |
crates/bevy_audio/src/lib.rs |
Adds the audio output and asset loaders. |
AudioSource |
crates/bevy_audio/src/audio_source.rs |
Asset; the decoded sample data. |
AudioPlayer |
crates/bevy_audio/src/audio.rs |
Component; spawn an entity with this to play a sound. |
PlaybackSettings |
crates/bevy_audio/src/audio.rs |
Volume, speed, looping, spatial. |
AudioSink / SpatialAudioSink |
crates/bevy_audio/src/sinks.rs |
Component that lets you control playback after spawn. |
How it works
AudioPlugin initializes a rodio output stream and stores the handle in a resource. A system watches for entities that have an AudioPlayer but no sink yet and creates one. Sinks update each frame from any setting changes. When an entity despawns or the sink reports empty, playback stops.
Spatial audio uses ear-pair attenuation and an optional HRTF when the relevant feature is on.
Integration points
- Depends on:
rodio,bevy_app,bevy_ecs,bevy_asset,bevy_math,bevy_transform. - Depended on by:
bevy_internal(default plugins).
Entry points for modification
- New audio format: add an
AssetLoaderinaudio_source.rs, gate by a cargo feature, add thedep:symphonia-...dependency inCargo.toml. - Custom decoder: implement
Decodablefor a type and register it as an asset. - Spatial improvements:
audio_output.rsandsinks.rs.
See also
bevy_assetfor the asset infrastructure.examples/audio/for runnable demos.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.