From 1daa841f312aa2e2d33d24d3930ce47e05a5e425 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Thu, 14 Jun 2018 10:07:25 +0300 Subject: [PATCH] PlayerWidget: Connect to the errors callback. --- hammond-gtk/src/app.rs | 2 +- hammond-gtk/src/widgets/player.rs | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/hammond-gtk/src/app.rs b/hammond-gtk/src/app.rs index 27e7d2e..6573f98 100644 --- a/hammond-gtk/src/app.rs +++ b/hammond-gtk/src/app.rs @@ -119,7 +119,7 @@ impl App { // Add the overlay to the main Box wrap.add(&overlay); - let player = PlayerWidget::new(); + let player = PlayerWidget::new(&sender); // Add the player to the main Box wrap.add(&player.action_bar); // player.reveal(); diff --git a/hammond-gtk/src/widgets/player.rs b/hammond-gtk/src/widgets/player.rs index 204cda5..5e29424 100644 --- a/hammond-gtk/src/widgets/player.rs +++ b/hammond-gtk/src/widgets/player.rs @@ -10,11 +10,13 @@ use gstreamer_player as gst_player; use gtk; use gtk::prelude::*; +use crossbeam_channel::Sender; use failure::Error; use hammond_data::{dbqueries, USER_AGENT}; use hammond_data::{EpisodeWidgetQuery, PodcastCoverQuery}; +use app::Action; use utils::set_image_from_path; use std::path::Path; @@ -160,20 +162,28 @@ impl Default for PlayerWidget { } impl PlayerWidget { - pub fn new() -> Rc { + pub fn new(sender: &Sender) -> Rc { let w = Rc::new(Self::default()); - Self::init(&w); + Self::init(&w, sender); w } #[cfg_attr(rustfmt, rustfmt_skip)] - fn init(s: &Rc) { + fn init(s: &Rc, sender: &Sender) { // Connect the play button to the gst Player. s.controls.play.connect_clicked(clone!(s => move |_| s.play())); // Connect the pause button to the gst Player. s.controls.pause.connect_clicked(clone!(s => move |_| s.pause())); + s.player.connect_error(clone!(sender => move |_, error| { + // FIXME: should never occur and should not be user facing. + sender.send(Action::ErrorNotification(format!("Player Error: {}", error))) + .map_err(|err| error!("Error: {}", err)) + .ok(); + + })); + Self::connect_timers(s); }