Commit efb685ac authored by Jordan Petridis's avatar Jordan Petridis

AudioPlayer: Wire the labels and slider to the gst_player.

parent aba59f61
......@@ -369,6 +369,7 @@ dependencies = [
"comrak 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"fractal-matrix-api 3.29.1",
"fragile 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"gdk 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gdk-pixbuf 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gdk-pixbuf-sys 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -418,6 +419,11 @@ dependencies = [
"urlencoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "fragile"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "fuchsia-zircon"
version = "0.3.3"
......@@ -802,7 +808,7 @@ dependencies = [
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"linkify 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"maplit 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
......@@ -2192,6 +2198,7 @@ dependencies = [
"checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
"checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
"checksum foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
"checksum fragile 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2ff777830a3bf2d15c62c51a5075bc928d912784c73303db630eecadba9cb5fc"
"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
"checksum futf 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "51f93f3de6ba1794dcd5810b3546d004600a59a98266487c8407bc4b24e398f3"
......
......@@ -28,6 +28,7 @@ gettext-rs = { git = "https://github.com/danigm/gettext-rs", branch = "no-gettex
regex = "1.0.0"
tree_magic = "0.2.0"
log = "0.4.2"
fragile = "0.2.1"
[dependencies.cairo-rs]
features = ["png"]
......
......@@ -27,6 +27,8 @@ extern crate gettextrs;
extern crate chrono;
extern crate fragile;
use fractal_api::backend;
use fractal_api::types;
use fractal_api::error;
......
......@@ -30,19 +30,20 @@ use glib::SignalHandlerId;
use chrono::NaiveTime;
use failure::Error;
use fragile::Fragile;
use std::ops::Deref;
use std::rc::Rc;
// use std::path::Path;
pub trait PlayerExt {
trait PlayerExt {
fn play(&self);
fn pause(&self);
fn stop(&self);
}
#[derive(Debug, Clone)]
pub struct PlayerTimes {
struct PlayerTimes {
container: gtk::Box,
progressed: gtk::Label,
duration: gtk::Label,
......@@ -51,7 +52,7 @@ pub struct PlayerTimes {
}
#[derive(Debug, Clone, Copy)]
pub struct Duration(ClockTime);
struct Duration(ClockTime);
impl Deref for Duration {
type Target = ClockTime;
......@@ -61,7 +62,7 @@ impl Deref for Duration {
}
#[derive(Debug, Clone, Copy)]
pub struct Position(ClockTime);
struct Position(ClockTime);
impl Deref for Position {
type Target = ClockTime;
......@@ -72,7 +73,7 @@ impl Deref for Position {
impl PlayerTimes {
/// Update the duration `gtk::Label` and the max range of the `gtk::SclaeBar`.
pub fn on_duration_changed(&self, duration: Duration) {
fn on_duration_changed(&self, duration: Duration) {
let seconds = duration.seconds().map(|v| v as f64).unwrap_or(0.0);
self.slider.block_signal(&self.slider_update);
......@@ -83,7 +84,7 @@ impl PlayerTimes {
}
/// Update the `gtk::SclaeBar` when the pipeline position is changed.
pub fn on_position_updated(&self, position: Position) {
fn on_position_updated(&self, position: Position) {
let seconds = position.seconds().map(|v| v as f64).unwrap_or(0.0);
self.slider.block_signal(&self.slider_update);
......@@ -116,12 +117,17 @@ pub struct PlayerWidget {
pub container: gtk::Box,
player: gst_player::Player,
controls: PlayerControls,
pub timer: PlayerTimes,
timer: PlayerTimes,
}
impl Default for PlayerWidget {
fn default() -> Self {
let player = gst_player::Player::new(None, None);
let dispatcher = gst_player::PlayerGMainContextSignalDispatcher::new(None);
let player = gst_player::Player::new(
None,
// Use the gtk main thread
Some(&dispatcher.upcast::<gst_player::PlayerSignalDispatcher>()),
);
let mut config = player.get_config();
config.set_position_update_interval(250);
......@@ -173,25 +179,7 @@ impl PlayerWidget {
#[cfg_attr(rustfmt, rustfmt_skip)]
fn init(s: &Rc<Self>) {
Self::connect_control_buttons(s);
// Log gst warnings.
s.player.connect_warning(move |_, warn| warn!("gst Warning: {}", warn));
// Log gst errors.
// This ideally will never occur.
s.player.connect_error(move |_, err| error!("gst Error: {}", err));
s.player.connect_duration_changed(move |_, clock| {
info!("Duration changed...");
});
s.player.connect_position_updated(move |_, clock| {
info!("Stream position updated");
});
s.player.connect_end_of_stream(move |player| {
info!("Stream ended");
});
Self::connect_gst_signals(s);
}
pub fn initialize_stream(&self) -> Result<(), Error> {
......@@ -208,6 +196,32 @@ impl PlayerWidget {
s.controls.pause.connect_clicked(clone!(s => move |_| s.pause()));
}
#[cfg_attr(rustfmt, rustfmt_skip)]
fn connect_gst_signals(s: &Rc<Self>) {
// Log gst warnings.
s.player.connect_warning(move |_, warn| warn!("gst warning: {}", warn));
// Log gst errors.
// This ideally will never occur.
s.player.connect_error(move |_, err| error!("gst Error: {}", err));
// The followign callbacks require `Send` but are handled by the gtk main loop
let s2 = Fragile::new(s.clone());
// Update the duration label and the slider
s.player.connect_duration_changed(clone!(s2 => move |_, clock| {
s2.get().timer.on_duration_changed(Duration(clock));
}));
// Update the position label and the slider
s.player.connect_position_updated(clone!(s2 => move |_, clock| {
s2.get().timer.on_position_updated(Position(clock));
}));
// Reset the slider to 0 and show a play button
s.player.connect_end_of_stream(clone!(s2 => move |_| s2.get().stop()));
}
fn connect_update_slider(slider: &gtk::Scale, player: &gst_player::Player) -> SignalHandlerId {
slider.connect_value_changed(clone!(player => move |slider| {
let value = slider.get_value() as u64;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment