Skip to content

Include audio file in executable #98

Answered by Roms1383
Mistera91 asked this question in Q&A
Discussion options

You must be logged in to vote

You already can actually!

include_bytes!() yields a &'static [u8; N], which implements AsRef<[u8]> + 'static and can be wrapped into a Cursor<&[u8]>, which both StaticSoundData and StreamingSoundData support with from_cursor :

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> =
        Aud…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Mistera91
Comment options

Answer selected by Mistera91
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants