load audio from user data dir and create UI
This commit is contained in:
parent
3845a729a2
commit
6235d564e4
|
@ -6,6 +6,7 @@ authors = ["Max Bradbury <max@tinybird.info>"]
|
|||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
dirs = "^3.0.1"
|
||||
gio = "^0"
|
||||
gtk = "^0"
|
||||
rodio = "^0.11.0"
|
||||
|
|
75
src/main.rs
75
src/main.rs
|
@ -14,29 +14,74 @@ fn build_ui(application: >k::Application) {
|
|||
window.set_title("lull");
|
||||
window.set_border_width(SPACING as u32);
|
||||
window.set_position(gtk::WindowPosition::Center);
|
||||
window.set_default_size(400, 100);
|
||||
window.set_default_size(256, 256);
|
||||
|
||||
let vertical = gtk::Box::new(Orientation::Vertical, SPACING);
|
||||
vertical.set_homogeneous(true);
|
||||
|
||||
window.add(&vertical);
|
||||
|
||||
// todo create user dir if it does not exist
|
||||
|
||||
// todo open user dir in file browser if it is empty
|
||||
|
||||
// todo iterate over audio files in user dir
|
||||
// todo create row for each audio file
|
||||
|
||||
window.show_all();
|
||||
|
||||
let device = rodio::default_output_device().unwrap();
|
||||
|
||||
let file = File::open("/home/max/being-harsh.mp3")
|
||||
.expect("Couldn't open audio file");
|
||||
let mut data_dir = dirs::data_dir().expect("Couldn't find user data directory");
|
||||
|
||||
let source = rodio::Decoder::new(BufReader::new(file))
|
||||
.expect("Couldn't decode audio");
|
||||
data_dir.push("ruin/lull");
|
||||
|
||||
rodio::play_raw(&device, source.convert_samples());
|
||||
if !data_dir.exists() {
|
||||
std::fs::create_dir_all(&data_dir).expect("Couldn't create lull data directory");
|
||||
}
|
||||
|
||||
let paths = std::fs::read_dir(&data_dir)
|
||||
.expect("Couldn't read from lull data directory");
|
||||
|
||||
for path in paths {
|
||||
let path = path.unwrap().path();
|
||||
let name: &str = path.file_stem().unwrap().to_str().unwrap();
|
||||
|
||||
let file = File::open(&path)
|
||||
.expect("Couldn't open audio file");
|
||||
|
||||
let source = rodio::Decoder::new(BufReader::new(file))
|
||||
.expect("Couldn't decode audio");
|
||||
|
||||
rodio::play_raw(&device, source.convert_samples());
|
||||
|
||||
let row = gtk::Box::new(Orientation::Horizontal, SPACING);
|
||||
row.set_homogeneous(true);
|
||||
|
||||
let label = gtk::Label::new(Some(name));
|
||||
row.add(&label);
|
||||
|
||||
let adjustment = gtk::Adjustment::new(
|
||||
0.0,
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0
|
||||
);
|
||||
|
||||
let slider = gtk::Scale::new(
|
||||
Orientation::Horizontal,
|
||||
Some(&adjustment)
|
||||
);
|
||||
|
||||
slider.set_draw_value(false);
|
||||
|
||||
row.add(&slider);
|
||||
|
||||
vertical.add(&row);
|
||||
}
|
||||
|
||||
let row_add = gtk::Box::new(Orientation::Horizontal, SPACING);
|
||||
row_add.set_homogeneous(true);
|
||||
|
||||
let button_open_dir = gtk::Button::with_label("add more");
|
||||
row_add.add(&button_open_dir);
|
||||
|
||||
vertical.add(&row_add);
|
||||
|
||||
window.show_all();
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
Loading…
Reference in New Issue