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.
This commit is contained in:
Chris Cochrun 2024-11-02 05:11:32 -05:00
parent 06debe1cc8
commit 99658ea060

View file

@ -1,9 +1,11 @@
use std::path::PathBuf;
use cosmic::{ use cosmic::{
dialog::ashpd::url::Url, dialog::ashpd::url::Url,
iced::{widget::text, ContentFit, Length}, iced::{widget::text, ContentFit, Length},
iced_widget::stack, iced_widget::stack,
prelude::*, prelude::*,
widget::{image, Container}, widget::{image, Container, Space},
Task, Task,
}; };
use iced_video_player::{Video, VideoPlayer}; use iced_video_player::{Video, VideoPlayer};
@ -16,7 +18,7 @@ use crate::core::slide::Slide;
pub(crate) struct Presenter { pub(crate) struct Presenter {
slides: Vec<Slide>, slides: Vec<Slide>,
current_slide: i16, current_slide: i16,
video: Video, video: Option<Video>,
} }
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
@ -32,14 +34,21 @@ impl Presenter {
slides: vec![slide], slides: vec![slide],
current_slide: 0, current_slide: 0,
video: { video: {
let url = Url::from_file_path("/home/chris/vids/test/camprules2024.mp4").unwrap(); if let Ok(path) =
let result = Video::new(&url); PathBuf::from("/home/chris/vids/test/chosensmol.mp4").canonicalize()
match result { {
Ok(v) => v, let url = Url::from_file_path(path).unwrap();
Err(e) => { let result = Video::new(&url);
// let root = e.source(); match result {
panic!("Error here: {e}") 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) .width(Length::Fill)
.height(Length::Fill), .height(Length::Fill),
); );
let video = Container::new( let vid_container;
VideoPlayer::new(&self.video) if let Some(video) = &self.video {
.width(Length::Fill) vid_container = Container::new(
.height(Length::Fill), VideoPlayer::new(video)
); .width(Length::Fill)
let stack = stack!(image, video, text) .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) .width(Length::Fill)
.height(Length::Fill); .height(Length::Fill);
stack.into() stack.into()