2022-01-05 22:30:15 +00:00
|
|
|
//! Audio support for the game engine Bevy
|
|
|
|
//!
|
2022-07-04 13:04:18 +00:00
|
|
|
//! ```no_run
|
2022-01-05 22:30:15 +00:00
|
|
|
//! # use bevy_ecs::{system::Res, event::EventWriter};
|
|
|
|
//! # use bevy_audio::{Audio, AudioPlugin};
|
|
|
|
//! # use bevy_asset::{AssetPlugin, AssetServer};
|
2022-07-04 13:04:18 +00:00
|
|
|
//! # use bevy_app::{App, AppExit, NoopPluginGroup as MinimalPlugins};
|
2022-01-05 22:30:15 +00:00
|
|
|
//! fn main() {
|
|
|
|
//! App::new()
|
|
|
|
//! .add_plugins(MinimalPlugins)
|
|
|
|
//! .add_plugin(AssetPlugin)
|
|
|
|
//! .add_plugin(AudioPlugin)
|
|
|
|
//! .add_startup_system(play_background_audio)
|
|
|
|
//! .run();
|
|
|
|
//! }
|
|
|
|
//!
|
|
|
|
//! fn play_background_audio(asset_server: Res<AssetServer>, audio: Res<Audio>) {
|
|
|
|
//! audio.play(asset_server.load("background_audio.ogg"));
|
|
|
|
//! }
|
|
|
|
//! ```
|
|
|
|
|
|
|
|
#![forbid(unsafe_code)]
|
|
|
|
#![warn(missing_docs)]
|
|
|
|
|
2020-10-20 18:44:50 +00:00
|
|
|
mod audio;
|
2020-07-16 20:46:51 +00:00
|
|
|
mod audio_output;
|
|
|
|
mod audio_source;
|
|
|
|
|
2022-01-05 22:30:15 +00:00
|
|
|
#[allow(missing_docs)]
|
2020-07-17 02:20:51 +00:00
|
|
|
pub mod prelude {
|
2021-04-27 18:29:33 +00:00
|
|
|
#[doc(hidden)]
|
2022-04-08 23:12:30 +00:00
|
|
|
pub use crate::{Audio, AudioOutput, AudioSource, Decodable, PlaybackSettings};
|
2020-07-17 02:20:51 +00:00
|
|
|
}
|
|
|
|
|
2021-02-18 21:20:37 +00:00
|
|
|
pub use audio::*;
|
|
|
|
pub use audio_output::*;
|
|
|
|
pub use audio_source::*;
|
|
|
|
|
2020-07-17 01:47:51 +00:00
|
|
|
use bevy_app::prelude::*;
|
2020-07-16 20:46:51 +00:00
|
|
|
use bevy_asset::AddAsset;
|
|
|
|
|
2022-01-05 22:30:15 +00:00
|
|
|
/// Adds support for audio playback to a Bevy Application
|
|
|
|
///
|
|
|
|
/// Use the [`Audio`] resource to play audio.
|
2020-07-16 20:46:51 +00:00
|
|
|
#[derive(Default)]
|
|
|
|
pub struct AudioPlugin;
|
|
|
|
|
2020-08-08 03:22:17 +00:00
|
|
|
impl Plugin for AudioPlugin {
|
2021-07-27 20:21:06 +00:00
|
|
|
fn build(&self, app: &mut App) {
|
2021-02-09 20:14:10 +00:00
|
|
|
app.init_non_send_resource::<AudioOutput<AudioSource>>()
|
2020-07-16 20:46:51 +00:00
|
|
|
.add_asset::<AudioSource>()
|
2022-03-01 01:12:11 +00:00
|
|
|
.add_asset::<AudioSink>()
|
2020-10-20 18:44:50 +00:00
|
|
|
.init_resource::<Audio<AudioSource>>()
|
2020-12-16 05:57:16 +00:00
|
|
|
.add_system_to_stage(
|
2021-02-18 21:20:37 +00:00
|
|
|
CoreStage::PostUpdate,
|
2022-04-25 14:32:56 +00:00
|
|
|
play_queued_audio_system::<AudioSource>,
|
2020-12-16 05:57:16 +00:00
|
|
|
);
|
2021-06-03 19:58:08 +00:00
|
|
|
|
|
|
|
#[cfg(any(feature = "mp3", feature = "flac", feature = "wav", feature = "vorbis"))]
|
2022-01-05 22:30:15 +00:00
|
|
|
app.init_asset_loader::<AudioLoader>();
|
2020-07-16 20:46:51 +00:00
|
|
|
}
|
|
|
|
}
|