Skip to content

Migrate to rodio 0.12 #638

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

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
2 changes: 1 addition & 1 deletion crates/bevy_audio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ bevy_ecs = { path = "../bevy_ecs", version = "0.2.1" }

# other
anyhow = "1.0"
rodio = { version = "0.11", default-features = false }
rodio = { version = "0.12", default-features = false }
parking_lot = "0.11.0"

[features]
Expand Down
18 changes: 13 additions & 5 deletions crates/bevy_audio/src/audio_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ use crate::{AudioSource, Decodable};
use bevy_asset::{Assets, Handle};
use bevy_ecs::Res;
use parking_lot::RwLock;
use rodio::{Device, Sink};
use std::collections::VecDeque;
use rodio::OutputStreamHandle;
use std::{collections::VecDeque};

/// Used to play audio on the current "audio device"
pub struct AudioOutput<P = AudioSource>
where
P: Decodable,
{
device: Device,
// device: Device,
// stream: Arc<Mutex<OutputStream>>,
stream_handle: OutputStreamHandle,
queue: RwLock<VecDeque<Handle<P>>>,
}

Expand All @@ -19,8 +21,12 @@ where
P: Decodable,
{
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(),
// device: rodio::default_output_device().unwrap(),
stream_handle,
queue: Default::default(),
}
}
Expand All @@ -33,8 +39,10 @@ where
<<P as Decodable>::Decoder as Iterator>::Item: rodio::Sample + Send + Sync,
{
pub fn play_source(&self, audio_source: &P) {
let sink = Sink::new(&self.device);
let sink = rodio::Sink::try_new(&self.stream_handle).unwrap();

sink.append(audio_source.decoder());

sink.detach();
}

Expand Down