//! This example illustrates how to load and play an audio file, and control how it's played. use bevy::{math::ops, prelude::*}; fn main() { App::new() .add_plugins(DefaultPlugins) .add_systems(Startup, setup) .add_systems( Update, (update_progress_text, update_speed, pause, mute, volume), ) .run(); } fn setup(mut commands: Commands, asset_server: Res) { commands.spawn(( AudioPlayer::new(asset_server.load("sounds/Windless Slopes.ogg")), MyMusic, )); commands.spawn(( Text::new(""), Node { position_type: PositionType::Absolute, top: Val::Px(12.0), left: Val::Px(12.0), ..default() }, ProgressText, )); // example instructions commands.spawn(( Text::new("-/=: Volume Down/Up\nSpace: Toggle Playback\nM: Toggle Mute"), Node { position_type: PositionType::Absolute, bottom: Val::Px(12.0), left: Val::Px(12.0), ..default() }, )); // camera commands.spawn(Camera3d::default()); } #[derive(Component)] struct MyMusic; #[derive(Component)] struct ProgressText; fn update_progress_text( music_controller: Single<&AudioSink, With>, mut progress_text: Single<&mut Text, With>, ) { progress_text.0 = format!("Progress: {}s", music_controller.position().as_secs_f32()); } fn update_speed(music_controller: Query<&AudioSink, With>, time: Res