implement play/pause and volume control
This commit is contained in:
parent
6235d564e4
commit
40c100e65b
18
src/main.rs
18
src/main.rs
|
@ -1,7 +1,7 @@
|
||||||
use gio::prelude::*;
|
use gio::prelude::*;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk::Orientation;
|
use gtk::Orientation;
|
||||||
use rodio::Source;
|
use rodio::Sink;
|
||||||
use std::env::args;
|
use std::env::args;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
|
@ -44,7 +44,9 @@ fn build_ui(application: >k::Application) {
|
||||||
let source = rodio::Decoder::new(BufReader::new(file))
|
let source = rodio::Decoder::new(BufReader::new(file))
|
||||||
.expect("Couldn't decode audio");
|
.expect("Couldn't decode audio");
|
||||||
|
|
||||||
rodio::play_raw(&device, source.convert_samples());
|
let sink = Sink::new(&device);
|
||||||
|
sink.append(source);
|
||||||
|
sink.pause();
|
||||||
|
|
||||||
let row = gtk::Box::new(Orientation::Horizontal, SPACING);
|
let row = gtk::Box::new(Orientation::Horizontal, SPACING);
|
||||||
row.set_homogeneous(true);
|
row.set_homogeneous(true);
|
||||||
|
@ -68,6 +70,18 @@ fn build_ui(application: >k::Application) {
|
||||||
|
|
||||||
slider.set_draw_value(false);
|
slider.set_draw_value(false);
|
||||||
|
|
||||||
|
slider.connect_value_changed(move |scale| {
|
||||||
|
let volume = scale.get_value();
|
||||||
|
println!("volume: {}", volume);
|
||||||
|
|
||||||
|
if volume == 0. {
|
||||||
|
sink.pause();
|
||||||
|
} else {
|
||||||
|
sink.play();
|
||||||
|
sink.set_volume(volume as f32);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
row.add(&slider);
|
row.add(&slider);
|
||||||
|
|
||||||
vertical.add(&row);
|
vertical.add(&row);
|
||||||
|
|
Loading…
Reference in New Issue