replit_audio 0.1.0

Rust library for playing audio in repl.it.
Documentation

replit_audio

Rust library for playing audio in repl.it.

Usage

Add

replit_audio = "0.1.0"

to your Cargo.toml file. This crate is available on crates.io.

Documentation is available on docs.rs.

You can view an example on repl.it. Tests should be ran on repl.it.

To play an audio file, create an Audio instance using the AudioBuilder:

let audio = AudioBuilder::new(&AudioType::File { file: FileType::Wav, path: "audio.wav".to_string() })
    .volume(1.0)
    .does_loop(true)
    .loop_count(-1)
    .build()
    .unwrap();

Then, you can obtain certain properties of the audio you played:

audio.get_duration().unwrap();
audio.get_remaining().unwrap();
audio.get_start_time().unwrap();
audio.get_end_time().unwrap();
audio.is_paused().unwrap();
// etc.

You can also play a tone:

let mut audio = AudioBuilder::new(&AudioType::Tone { tone: ToneType::Square, pitch: 440.0, duration: 2.0 })
    .build()
    .unwrap();

It is possible to update a playing audio instance:

audio.update(&AudioUpdate { volume: 0.1, paused: false, does_loop: false, loop_count: -1 }).unwrap();

License

MIT