From b92437ba33e7f790e352370b7eeb117cf8e12994 Mon Sep 17 00:00:00 2001 From: Tunahan Karlibas Date: Mon, 24 Aug 2020 01:52:30 +0300 Subject: [PATCH] Use git version of the rodio to fix the audio issue on macOS --- assets/.DS_Store | Bin 0 -> 6148 bytes crates/bevy_audio/Cargo.toml | 2 +- crates/bevy_audio/src/audio_output.rs | 17 +++++++++++------ 3 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 assets/.DS_Store diff --git a/assets/.DS_Store b/assets/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..65ae1e539b2634f29a84bc41ab85a2cfabff5855 GIT binary patch literal 6148 zcmeHK&1%~~5T141RH~t<&_e<}EcDQe4{j6c<|f>vr$R~PkS`IdqYv@S5f+HvwG z&!*$x{&TJBI9FL|>e(9a4s(_2=}0#!txUWtZtPcaJ;6HO!!VYHPv7&$!NzR1{cPBm zTTgc8eK{Kr2YtD{^>jY>J#X{Ti`O5T&nKs6U%r0({^Q(afxr*e$UTP(_=(06A;(dv z3avh&f046@Wn>1J0cPNaGT^o|uXjW5pKqHPU!BJY%Sspim<7OHdVMIhOp`Amo6@J*jlvdAk4~G$E_^f2}PLI(JxInh|nUB z%m6d6%)pwx45DD6X~mI|U8X hiZPa2@dm09^h+`jLx-(J^q}yMfT4j0X5gVo?A9 literal 0 HcmV?d00001 diff --git a/crates/bevy_audio/Cargo.toml b/crates/bevy_audio/Cargo.toml index 8350ee942842b..5a6c5953a9537 100644 --- a/crates/bevy_audio/Cargo.toml +++ b/crates/bevy_audio/Cargo.toml @@ -17,7 +17,7 @@ bevy_ecs = {path = "../bevy_ecs", version = "0.1"} # other anyhow = "1.0" -rodio = {version = "0.11", default-features = false} +rodio = { git = "https://github.com/RustAudio/rodio", default-features = false} parking_lot = "0.10.2" [features] diff --git a/crates/bevy_audio/src/audio_output.rs b/crates/bevy_audio/src/audio_output.rs index d81157070d9b8..ed5cb6c48a2a4 100644 --- a/crates/bevy_audio/src/audio_output.rs +++ b/crates/bevy_audio/src/audio_output.rs @@ -2,19 +2,23 @@ use crate::AudioSource; use bevy_asset::{Assets, Handle}; use bevy_ecs::Res; use parking_lot::RwLock; -use rodio::{Decoder, Device, Sink}; +use rodio::OutputStreamHandle; use std::{collections::VecDeque, io::Cursor}; /// Used to play audio on the current "audio device" pub struct AudioOutput { - device: Device, + // stream: Arc>, + stream_handle: OutputStreamHandle, queue: RwLock>>, } impl Default for AudioOutput { fn default() -> Self { + let (stream, stream_handle) = + rodio::OutputStream::try_default().expect("Can't get an output stream"); + std::mem::forget(stream); Self { - device: rodio::default_output_device().unwrap(), + stream_handle, queue: Default::default(), } } @@ -22,9 +26,10 @@ impl Default for AudioOutput { impl AudioOutput { pub fn play_source(&self, audio_source: &AudioSource) { - let sink = Sink::new(&self.device); - sink.append(Decoder::new(Cursor::new(audio_source.clone())).unwrap()); - sink.detach(); + self.stream_handle + .play_once(Cursor::new(audio_source.clone())) + .unwrap() + .detach(); } pub fn play(&self, audio_source: Handle) {