Skip to content

Commit b85a940

Browse files
committed
Fixes disable-audio.patch
1 parent 51b8311 commit b85a940

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed
Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,35 @@
11
diff --git a/crates/bevy_audio/src/audio_output.rs b/crates/bevy_audio/src/audio_output.rs
2-
index 3e8082e23..624769443 100644
2+
index 15236b667..57f116bde 100644
33
--- a/crates/bevy_audio/src/audio_output.rs
44
+++ b/crates/bevy_audio/src/audio_output.rs
5-
@@ -7,7 +7,7 @@ use bevy_ecs::{prelude::*, system::SystemParam};
5+
@@ -6,28 +6,17 @@ use bevy_asset::{Asset, Assets};
6+
use bevy_ecs::{prelude::*, system::SystemParam};
67
use bevy_math::Vec3;
78
use bevy_transform::prelude::GlobalTransform;
8-
-use rodio::{OutputStream, OutputStreamHandle, Sink, Source, SpatialSink};
9-
+use rodio::{OutputStreamHandle, Sink, Source, SpatialSink};
9+
-use rodio::{OutputStream, OutputStreamBuilder, Sink, Source, SpatialSink};
10+
+use rodio::{OutputStream, Sink, Source, SpatialSink};
1011
use tracing::warn;
1112

1213
use crate::{AudioSink, AudioSinkPlayback};
1314

14-
@@ -30,18 +30,10 @@ pub(crate) struct AudioOutput {
15-
16-
impl Default for AudioOutput {
17-
fn default() -> Self {
18-
- if let Ok((stream, stream_handle)) = OutputStream::try_default() {
19-
- // We leak `OutputStream` to prevent the audio from stopping.
20-
- core::mem::forget(stream);
21-
- Self {
22-
- stream_handle: Some(stream_handle),
23-
- }
24-
- } else {
25-
warn!("No audio device found.");
26-
Self {
27-
stream_handle: None,
28-
}
29-
- }
30-
}
15+
/// Used internally to play audio on the current "audio device"
16+
-#[derive(Resource)]
17+
+#[derive(Resource, Default)]
18+
pub(crate) struct AudioOutput {
19+
stream: Option<OutputStream>,
3120
}
3221

22+
-impl Default for AudioOutput {
23+
- fn default() -> Self {
24+
- let stream = OutputStreamBuilder::open_default_stream()
25+
- .inspect_err(|_err| {
26+
- warn!("No audio device found.");
27+
- })
28+
- .ok();
29+
- Self { stream }
30+
- }
31+
-}
32+
-
33+
/// Marker for internal use, to despawn entities when playback finishes.
34+
#[derive(Component, Default)]
35+
pub struct PlaybackDespawnMarker;

0 commit comments

Comments
 (0)