From 99658ea060d52d211726eff11dde20af591bf055 Mon Sep 17 00:00:00 2001 From: Chris Cochrun <chris@cochrun.xyz> Date: Sat, 2 Nov 2024 05:11:32 -0500 Subject: [PATCH] working video_player in iced..... This means that we have achieved what we've set out for. All the pieces are available to us to use, we just now have to build it. --- src/ui/presenter.rs | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/src/ui/presenter.rs b/src/ui/presenter.rs index eed370b..f56369e 100644 --- a/src/ui/presenter.rs +++ b/src/ui/presenter.rs @@ -1,9 +1,11 @@ +use std::path::PathBuf; + use cosmic::{ dialog::ashpd::url::Url, iced::{widget::text, ContentFit, Length}, iced_widget::stack, prelude::*, - widget::{image, Container}, + widget::{image, Container, Space}, Task, }; use iced_video_player::{Video, VideoPlayer}; @@ -16,7 +18,7 @@ use crate::core::slide::Slide; pub(crate) struct Presenter { slides: Vec<Slide>, current_slide: i16, - video: Video, + video: Option<Video>, } #[derive(Debug, Clone, PartialEq, Eq)] @@ -32,14 +34,21 @@ impl Presenter { slides: vec![slide], current_slide: 0, video: { - let url = Url::from_file_path("/home/chris/vids/test/camprules2024.mp4").unwrap(); - let result = Video::new(&url); - match result { - Ok(v) => v, - Err(e) => { - // let root = e.source(); - panic!("Error here: {e}") + if let Ok(path) = + PathBuf::from("/home/chris/vids/test/chosensmol.mp4").canonicalize() + { + let url = Url::from_file_path(path).unwrap(); + let result = Video::new(&url); + match result { + Ok(v) => Some(v), + Err(e) => { + error!("Had an error creating the video object: {e}"); + None + } } + } else { + error!("File doesn't exist: "); + None } }, } @@ -73,12 +82,18 @@ impl Presenter { .width(Length::Fill) .height(Length::Fill), ); - let video = Container::new( - VideoPlayer::new(&self.video) - .width(Length::Fill) - .height(Length::Fill), - ); - let stack = stack!(image, video, text) + let vid_container; + if let Some(video) = &self.video { + vid_container = Container::new( + VideoPlayer::new(video) + .width(Length::Fill) + .height(Length::Fill) + .content_fit(ContentFit::Cover), + ); + } else { + vid_container = Container::new(Space::new(0, 0)); + } + let stack = stack!(image, vid_container, text) .width(Length::Fill) .height(Length::Fill); stack.into()