Don't abstract player

This commit is contained in:
Vladimir Borisov 2021-07-15 15:46:02 +03:00
parent 803fc0c3c0
commit 5395c278a3
No known key found for this signature in database
GPG key ID: F9A584BE4FCB6603
3 changed files with 9 additions and 35 deletions

View file

@ -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();

View file

@ -1,2 +1,2 @@
pub mod stremio_player;
pub use stremio_player::{Player, PlayerInterface};
pub use stremio_player::Player;

View file

@ -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<Option<mpv::MpvHandler>>,
}
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<T: mpv::MpvFormat>(&self, prop: &str, val: T) {
pub fn set_prop<T: mpv::MpvFormat>(&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<W: Into<nwg::ControlHandle>>(
data: &mut Self,
parent: Option<W>,
) -> Result<(), nwg::NwgError> {
let mut mpv_builder =
mpv::MpvHandlerBuilder::new().expect("Error while creating MPV builder");
mpv_builder