Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use git version of the rodio to fix the audio issue on macOS #310

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion crates/bevy_audio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
17 changes: 11 additions & 6 deletions crates/bevy_audio/src/audio_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,34 @@ 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<Mutex<OutputStream>>,
stream_handle: OutputStreamHandle,
queue: RwLock<VecDeque<Handle<AudioSource>>>,
}

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(),
}
}
}

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<AudioSource>) {
Expand Down