Repository navigation
|
Hello ! |
Answered by
Roms1383
Jun 13, 2024
Replies: 1 comment 1 reply
|
You already can actually!
use kira::{
manager::{AudioManager, AudioManagerSettings, DefaultBackend},
sound::static_sound::StaticSoundData,
};
fn main() {
use std::io::Cursor;
let bytes = include_bytes!("wild-cherry-play-that-funky-music.mp3");
let cursor = Cursor::new(bytes);
let data = StaticSoundData::from_cursor(cursor).expect("read static sound data from cursor");
let duration = data.duration();
let mut manager: AudioManager<DefaultBackend> =
AudioManager::new(AudioManagerSettings::default()).expect("audio manager");
manager.play(data).expect("play sound data");
std::thread::sleep(duration);
// depending on its size, you can experience some latency before sound gets loaded in memory and played
} |
1 reply
Answer selected by
Mistera91
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You already can actually!
include_bytes!()yields a&'static [u8; N], which implementsAsRef<[u8]> + 'staticand can be wrapped into aCursor<&[u8]>, which bothStaticSoundDataandStreamingSoundDatasupport with from_cursor :