replit_audio

Crates.ioreplit_audio
lib.rsreplit_audio
version0.1.0
sourcesrc
created_at2020-08-20 00:47:42.33604
updated_at2020-08-20 00:47:42.33604
descriptionRust library for playing audio in repl.it.
homepage
repositoryhttps://github.com/Daniel-Liu-c0deb0t/replit_audio
max_upload_size
id278469
size16,903
Daniel Liu (Daniel-Liu-c0deb0t)

documentation

https://docs.rs/replit_audio

README

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

Commit count: 12

cargo fmt