use iced_video::{Video, VideoHandle}; pub fn main() -> iced::Result { use tracing_subscriber::prelude::*; tracing_subscriber::registry() .with( tracing_subscriber::fmt::layer() .with_thread_ids(true) .with_file(true), ) .with(tracing_subscriber::EnvFilter::from_default_env()) .init(); iced::application(State::new, update, view) .subscription(keyboard_event) .run() } fn keyboard_event(state: &State) -> iced::Subscription { use iced::keyboard::{Key, key::Named}; iced::keyboard::listen().map(move |event| match event { iced::keyboard::Event::KeyPressed { key, .. } => { let key = key.as_ref(); match key { Key::Named(Named::Escape) | Key::Character("q") => Message::Quit, Key::Named(Named::Space) => Message::Toggle, _ => Message::Load, } // if key == &space { // // Toggle play/pause // let is_playing = state // .video // .source() // .is_playing() // .expect("Failed to get playing state"); // if is_playing { // Message::Pause // } else { // Message::Play // } // } } _ => Message::Load, }) } #[derive(Debug, Clone)] pub struct State { video: VideoHandle, } impl State { pub fn new() -> Self { let video = VideoHandle::new("https://jellyfin.tsuba.darksailor.dev/Items/6010382cf25273e624d305907010d773/Download?api_key=036c140222464878862231ef66a2bc9c") .expect("Failed to create video handle"); // let video = VideoHandle::new("file:///run/user/1000/gvfs/smb-share:server=tsuba.darksailor.dev,share=nas/Movies/Spider-Man - No Way Home (2021)/Spider-Man.No.Way.Home.2021.UHD.BluRay.2160p.TrueHD.Atmos.7.1.DV.HEVC.REMUX-FraMeSToR.mkv") // .expect("Failed to create video handle"); Self { video } } } #[derive(Debug, Clone, Copy)] pub enum Message { Play, Pause, Toggle, Load, Quit, } pub fn update(state: &mut State, message: Message) -> iced::Task { match message { Message::Load => { // does stuff // let src = state.video.source().clone(); // iced::Task::perform(src.wait(), |_| Message::Loaded) iced::Task::none() } Message::Play => { state.video.source().play().expect("Failed to play video"); iced::Task::none() } Message::Pause => { state.video.source().pause().expect("Failed to pause video"); iced::Task::none() } Message::Toggle => { state.video.source().toggle().expect("Failed to stop video"); iced::Task::none() } Message::Quit => { state.video.source().stop().expect("Failed to stop video"); std::process::exit(0); } } } pub fn view<'a>(state: &'a State) -> iced::Element<'a, Message> { let video_widget = Video::new(&state.video) .width(iced::Length::Fill) .height(iced::Length::Fill) .content_fit(iced::ContentFit::Contain); iced::widget::Column::new() .push(video_widget) .push( iced::widget::Row::new() .push(iced::widget::Button::new("Play").on_press(Message::Play)) .push(iced::widget::Button::new("Pause").on_press(Message::Pause)) .spacing(5) .padding(10) .align_y(iced::Alignment::Center), ) .align_x(iced::Alignment::Center) .into() }