mirror of
https://github.com/bevyengine/bevy.git
synced 2026-06-30 15:55:32 -04:00
17a1b081cb
# Objective - All Bevy programs with bevy_audio print a line to stderr when they exit: ``` Dropping DeviceSink, audio playing through this sink will stop, to prevent this message from appearing use tracing or call `.log_on_drop(false)` on this DeviceSink ``` - This is an expected print by rodio: https://github.com/RustAudio/rodio/blob/7e9ba6dd017abb88a1de8c287849c89c3624437d/src/stream.rs#L99-L108 ## Solution - Enable the tracing feature so that it's logged instead of printed - set `log_on_drop(false)` on the audio sink created by Bevy. It's expected to stop playing sound when it's dropped
40 lines
1.3 KiB
Diff
40 lines
1.3 KiB
Diff
diff --git a/crates/bevy_audio/src/audio_output.rs b/crates/bevy_audio/src/audio_output.rs
|
|
index 1b23ccee8..4de2412fa 100644
|
|
--- a/crates/bevy_audio/src/audio_output.rs
|
|
+++ b/crates/bevy_audio/src/audio_output.rs
|
|
@@ -6,32 +6,17 @@ use bevy_asset::{Asset, Assets};
|
|
use bevy_ecs::{prelude::*, system::SystemParam};
|
|
use bevy_math::Vec3;
|
|
use bevy_transform::prelude::GlobalTransform;
|
|
-use rodio::{DeviceSinkBuilder, MixerDeviceSink, Player, Source, SpatialPlayer};
|
|
+use rodio::{MixerDeviceSink, Player, Source, SpatialPlayer};
|
|
use tracing::warn;
|
|
|
|
use crate::{AudioSink, AudioSinkPlayback};
|
|
|
|
/// Used internally to play audio on the current "audio device"
|
|
-#[derive(Resource)]
|
|
+#[derive(Resource, Default)]
|
|
pub(crate) struct AudioOutput {
|
|
stream: Option<MixerDeviceSink>,
|
|
}
|
|
|
|
-impl Default for AudioOutput {
|
|
- fn default() -> Self {
|
|
- let stream = DeviceSinkBuilder::open_default_sink()
|
|
- .inspect_err(|_err| {
|
|
- warn!("No audio device found.");
|
|
- })
|
|
- .map(|mut s| {
|
|
- s.log_on_drop(false);
|
|
- s
|
|
- })
|
|
- .ok();
|
|
- Self { stream }
|
|
- }
|
|
-}
|
|
-
|
|
/// Marker for internal use, to despawn entities when playback finishes.
|
|
#[derive(Component, Default)]
|
|
pub struct PlaybackDespawnMarker;
|