Crates.io | replit_audio |
lib.rs | replit_audio |
version | 0.1.0 |
source | src |
created_at | 2020-08-20 00:47:42.33604 |
updated_at | 2020-08-20 00:47:42.33604 |
description | Rust library for playing audio in repl.it. |
homepage | |
repository | https://github.com/Daniel-Liu-c0deb0t/replit_audio |
max_upload_size | |
id | 278469 |
size | 16,903 |
Rust library for playing audio in repl.it.
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();