From f0d5a1c645c4d849ced8c6d5a3fa41bcd077748c Mon Sep 17 00:00:00 2001 From: Vladimir Borisov Date: Mon, 23 Dec 2024 14:03:26 +0200 Subject: [PATCH] Fix playback from offset --- .../stremio_player/communication.rs | 8 +++++ src/stremio_app/stremio_player/player.rs | 33 ++++++++++++++++--- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/stremio_app/stremio_player/communication.rs b/src/stremio_app/stremio_player/communication.rs index 39170c6..990920a 100644 --- a/src/stremio_app/stremio_player/communication.rs +++ b/src/stremio_app/stremio_player/communication.rs @@ -231,12 +231,20 @@ stringable!(MpvCmd); pub enum CmdVal { Single((MpvCmd,)), Double(MpvCmd, String), + Tripple(MpvCmd, String, String), + Quadruple(MpvCmd, String, String, String), + Quintuple(MpvCmd, String, String, String, String), } impl From for Vec { fn from(cmd: CmdVal) -> Vec { match cmd { CmdVal::Single(cmd) => vec![cmd.0.to_string()], CmdVal::Double(cmd, arg) => vec![cmd.to_string(), arg], + CmdVal::Tripple(cmd, arg1, arg2) => vec![cmd.to_string(), arg1, arg2], + CmdVal::Quadruple(cmd, arg1, arg2, arg3) => vec![cmd.to_string(), arg1, arg2, arg3], + CmdVal::Quintuple(cmd, arg1, arg2, arg3, arg4) => { + vec![cmd.to_string(), arg1, arg2, arg3, arg4] + } } } } diff --git a/src/stremio_app/stremio_player/player.rs b/src/stremio_app/stremio_player/player.rs index 95d0d8b..0d66d15 100644 --- a/src/stremio_app/stremio_player/player.rs +++ b/src/stremio_app/stremio_player/player.rs @@ -160,11 +160,36 @@ fn create_message_thread( }; let send_command = |cmd: CmdVal| { - let (name, arg) = match cmd { - CmdVal::Double(name, arg) => (name, format!(r#""{arg}""#)), - CmdVal::Single((name,)) => (name, String::new()), + let a1; + let a2; + let a3; + let a4; + let (name, args) = match cmd { + CmdVal::Quintuple(name, arg1, arg2, arg3, arg4) => { + a1 = format!(r#""{arg1}""#); + a2 = format!(r#""{arg2}""#); + a3 = format!(r#""{arg3}""#); + a4 = format!(r#""{arg4}""#); + (name, vec![a1.as_ref(), a2.as_ref(), a3.as_ref(), a4.as_ref()]) + } + CmdVal::Quadruple(name, arg1, arg2, arg3) => { + a1 = format!(r#""{arg1}""#); + a2 = format!(r#""{arg2}""#); + a3 = format!(r#""{arg3}""#); + (name, vec![a1.as_ref(), a2.as_ref(), a3.as_ref()]) + } + CmdVal::Tripple(name, arg1, arg2 ) => { + a1 = format!(r#""{arg1}""#); + a2 = format!(r#""{arg2}""#); + (name, vec![a1.as_ref(), a2.as_ref()]) + }, + CmdVal::Double(name, arg1) => { + a1 = format!(r#""{arg1}""#); + (name, vec![a1.as_ref()]) + } + CmdVal::Single((name,)) => (name, vec![]), }; - if let Err(error) = mpv.command(&name.to_string(), &[&arg]) { + if let Err(error) = mpv.command(&name.to_string(), &args) { eprintln!("failed to execute MPV command: '{error:#}'") } };