[gnome-tour/bilelmoussaoui/video] correctly play the video, avoid looping
- From: Bilal Elmoussaoui <bilelmoussaoui src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-tour/bilelmoussaoui/video] correctly play the video, avoid looping
- Date: Tue, 18 Aug 2020 15:42:26 +0000 (UTC)
commit 1c24350af2495d8c3078fa849eba36db66c82a44
Author: Bilal Elmoussaoui <bil elmoussaoui gmail com>
Date: Tue Aug 18 17:41:55 2020 +0200
correctly play the video, avoid looping
src/widgets/pages/welcome.rs | 34 +++++++++++++++++++++-------------
1 file changed, 21 insertions(+), 13 deletions(-)
---
diff --git a/src/widgets/pages/welcome.rs b/src/widgets/pages/welcome.rs
index 8c40d0a..82f58fe 100644
--- a/src/widgets/pages/welcome.rs
+++ b/src/widgets/pages/welcome.rs
@@ -15,6 +15,7 @@ use std::cell::RefCell;
#[cfg(feature = "video")]
pub enum Action {
VideoReady,
+ VideoUp,
}
pub struct WelcomePageWidget {
@@ -105,27 +106,34 @@ impl WelcomePageWidget {
#[cfg(feature = "video")]
{
let receiver = self.receiver.borrow_mut().take().unwrap();
- receiver.attach(None, move |action| {
- if action == Action::VideoReady {
- header.get_style_context().add_class("playing");
- }
- glib::Continue(true)
- });
-
- let video_file = gio::File::new_for_path(config::VIDEO_PATH);
- self.player.set_uri(&video_file.get_uri());
+ receiver.attach(
+ None,
+ clone!(@strong self.player as player => move |action| {
+ match action {
+ Action::VideoReady => player.play(),
+ Action::VideoUp => header.get_style_context().add_class("playing"),
+ };
+ glib::Continue(true)
+ }),
+ );
- self.player.connect_state_changed(clone!(@strong self.sender as sender => move |_, state| {
+ self.player.connect_state_changed(clone!(@strong self.sender as sender => move |_p,state| {
if state == gst_player::PlayerState::Playing {
- sender.send(Action::VideoReady).unwrap();
+ sender.send(Action::VideoUp).unwrap();
}
}));
+ self.player.connect_uri_loaded(clone!(@strong self.sender as sender => move |_p, _uri| {
+ sender.send(Action::VideoReady).unwrap();
+ }));
+ self.player.connect_end_of_stream(move |p| p.stop());
+
+ let video_file = gio::File::new_for_path(config::VIDEO_PATH);
gtk::timeout_add(
500,
clone!(@strong self.player as player => move || {
- player.play();
- glib::Continue(true)
+ player.set_uri(&video_file.get_uri());
+ glib::Continue(false)
}),
);
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]