-
Notifications
You must be signed in to change notification settings - Fork 293
Closed as duplicate of#832
Description
I'm using Windows 11, rodio is working normally without Buffered.
//builtin.rs
pub fn preload() {
log("Loading built-in looped audio...");
let _ = &BUILTIN_LOOP_SOURCES;
log("Built-in looped audio loaded.");
}
pub static BUILTIN_LOOP_SOURCES: LazyLock<
HashMap<&'static str, Buffered<LoopedDecoder<Cursor<&'static [u8]>>>>,
> = LazyLock::new(|| load("Looped", BUILTIN_LOOP_AUDIOS, Decoder::new_looped));
pub fn load<T: Source>(
audio_type: &str,
list: &'static [(&str, &[u8])],
func: fn(Cursor<&'static [u8]>) -> Result<T, DecoderError>,
) -> HashMap<&'static str, Buffered<T>> {
let mut map = HashMap::new();
for (name, bytes) in list.iter() {
let cursor = Cursor::new(*bytes);
let decoder = match func(cursor) {
Ok(decoder) => {
log(&format!("Loaded built-in {} audio: {}", audio_type, name));
decoder
}
Err(err) => {
log_error(&format!(
"Failed to load built-in {} audio {}: {}",
audio_type, name, err
));
continue;
}
};
map.insert(*name, decoder.buffered());
}
map
}
pub static BUILTIN_LOOP_AUDIOS: &[(&str, &[u8])] =
&[("domingo", DOMINGO_AUDIO), ("kitty", KITTY_AUDIO)];
pub static DOMINGO_AUDIO: &[u8] = include_bytes!("../../assets/domingo.ogg");
pub static KITTY_AUDIO: &[u8] = include_bytes!("../../assets/kitty.ogg");//engine.rs
pub struct AudioEngine {
_stream_handle: OutputStream,
background_sink: Sink,
}
impl AudioEngine {
pub fn new() -> Result<Self, Error> {
let mut stream_handle = OutputStreamBuilder::open_default_stream()?;
stream_handle.log_on_drop(DEBUGGER.enabled);
let background_sink = Sink::connect_new(stream_handle.mixer());
Ok(Self {
_stream_handle: stream_handle,
background_sink,
})
}
pub fn play_looped<T: Source + Send + 'static>(
&self,
name: &str,
source: T,
) -> Result<(), DecoderError> {
log(&format!("Playing looped audio: {name}"));
self.background_sink.append(source);
let sink_len = self.background_sink.len();
log(&format!("Background sink length: {}", sink_len));
for _ in 1..sink_len {
log(&format!("Skipping one in background sink..."));
self.background_sink.skip_one();
}
Ok(())
}
pub fn get_builtin_looped(
&self,
name: &str,
) -> Option<Buffered<LoopedDecoder<Cursor<&'static [u8]>>>> {
match BUILTIN_LOOP_SOURCES.get(name) {
Some(audio) => Some(audio.clone()),
None => {
log_error(&format!("Builtin looped audio {} not found!", name));
None
}
}
}
pub fn play_domingo(&self) {
let Some(domingo) = self.get_builtin_looped("domingo") else {
return;
};
let _ = self
.play_looped("builtin::DOMINGO", domingo)
.inspect_err(|e| log_error(&format!("Can't play builtin DOMINGO: {}", e)));
}
pub fn play_kitty(&self) {
let Some(kitty) = self.get_builtin_looped("kitty") else {
return;
};
let _ = self
.play_looped("builtin::KITTY", kitty)
.inspect_err(|e| log_error(&format!("Can't play builtin KITTY: {}", e)));
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels