mirror of
https://github.com/Stremio/stremio-shell-ng.git
synced 2026-03-11 17:15:49 +00:00
Don't abstract player
This commit is contained in:
parent
803fc0c3c0
commit
5395c278a3
3 changed files with 9 additions and 35 deletions
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
pub mod stremio_player;
|
||||
pub use stremio_player::{Player, PlayerInterface};
|
||||
pub use stremio_player::Player;
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue