From 5395c278a358963274ba0567bb15eb4eba86b55f Mon Sep 17 00:00:00 2001 From: Vladimir Borisov Date: Thu, 15 Jul 2021 15:46:02 +0300 Subject: [PATCH] Don't abstract player --- src/stremio_app/stremio_app.rs | 11 ++++--- src/stremio_app/stremio_player/mod.rs | 2 +- .../stremio_player/stremio_player.rs | 31 ++----------------- 3 files changed, 9 insertions(+), 35 deletions(-) diff --git a/src/stremio_app/stremio_app.rs b/src/stremio_app/stremio_app.rs index a68ac0d..3448e6c 100644 --- a/src/stremio_app/stremio_app.rs +++ b/src/stremio_app/stremio_app.rs @@ -2,7 +2,7 @@ use native_windows_derive::NwgUi; use native_windows_gui as nwg; use std::cmp; -use crate::stremio_app::stremio_player::{Player, PlayerInterface}; +use crate::stremio_app::stremio_player::Player; use crate::stremio_app::stremio_wevbiew::WebView; #[derive(Default, NwgUi)] @@ -28,10 +28,11 @@ impl MainWindow { self.window.set_position(x, y); // let video_path = "/home/ivo/storage/bbb_sunflower_1080p_30fps_normal.mp4"; let video_path = "http://distribution.bbb3d.renderfarming.net/video/mp4/bbb_sunflower_1080p_30fps_normal.mp4"; - self.player.play(video_path); - // self.player.seek(120.0); - self.player.speed(2.0); - // self.player.pause(true); + self.player.command(&["loadfile", video_path]); + // self.player.set_prop("time-pos", 120.0); + self.player.set_prop("speed", 2.0); + // self.player.set_prop("pause", true); + self.player.command(&["stop"]); } fn on_quit(&self) { nwg::stop_thread_dispatch(); diff --git a/src/stremio_app/stremio_player/mod.rs b/src/stremio_app/stremio_player/mod.rs index 5bbd796..6a11b83 100644 --- a/src/stremio_app/stremio_player/mod.rs +++ b/src/stremio_app/stremio_player/mod.rs @@ -1,2 +1,2 @@ pub mod stremio_player; -pub use stremio_player::{Player, PlayerInterface}; \ No newline at end of file +pub use stremio_player::Player; \ No newline at end of file diff --git a/src/stremio_app/stremio_player/stremio_player.rs b/src/stremio_app/stremio_player/stremio_player.rs index 55d8945..4748cf8 100644 --- a/src/stremio_app/stremio_player/stremio_player.rs +++ b/src/stremio_app/stremio_player/stremio_player.rs @@ -1,28 +1,20 @@ use native_windows_gui::{self as nwg, PartialUi}; use std::cell::RefCell; -pub trait PlayerInterface { - fn play(&self, media_path: &str); - fn pause(&self, paused: bool); - fn seek(&self, time: f64); - fn speed(&self, factor: f64); - fn stop(&self); -} - #[derive(Default)] pub struct Player { mpv: RefCell>, } impl Player { - fn command(&self, args: &[&str]) { + pub fn command(&self, args: &[&str]) { let mut mpv = self.mpv.borrow_mut(); let mpv = mpv.as_mut().expect("Failed to create MPV"); if let Err(e) = mpv.command(args) { eprintln!("Failed to execute command {:?} - {:?}", args, e); } } - fn set_prop(&self, prop: &str, val: T) { + pub fn set_prop(&self, prop: &str, val: T) { let mut mpv = self.mpv.borrow_mut(); let mpv = mpv.as_mut().expect("Failed to create MPV"); if let Err(e) = mpv.set_property(prop, val) { @@ -31,30 +23,11 @@ impl Player { } } -impl PlayerInterface for Player { - fn play(&self, media_path: &str) { - self.command(&["loadfile", media_path]); - } - fn pause(&self, paused: bool) { - self.set_prop("pause", paused); - } - fn seek(&self, pos: f64) { - self.set_prop("time-pos", pos); - } - fn speed(&self, factor: f64) { - self.set_prop("speed", factor); - } - fn stop(&self) { - self.command(&["stop"]); - } -} - impl PartialUi for Player { fn build_partial>( data: &mut Self, parent: Option, ) -> Result<(), nwg::NwgError> { - let mut mpv_builder = mpv::MpvHandlerBuilder::new().expect("Error while creating MPV builder"); mpv_builder