Playing a video.

This commit is contained in:
Tom Alexander 2022-02-20 21:36:42 -05:00
parent f28057352f
commit eb9bfb7862
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 22 additions and 0 deletions

View File

@ -1,6 +1,7 @@
use sqlx::sqlite::SqliteConnectOptions;
use sqlx::sqlite::SqlitePool;
use std::env;
use std::path::Path;
use std::process::Stdio;
use std::str::FromStr;
use tokio::io::{AsyncBufReadExt, BufReader};
@ -50,6 +51,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut mpvctl = MpvCtl::connect("/tmp/recordwatchsocket").await?;
let client_name = mpvctl.get_client_name().await?;
let _ = mpvctl
.play_video("/home/talexander/Downloads/test.mp4")
.await?;
sleep(Duration::from_secs(5)).await;
println!("done {}", client_name);

View File

@ -129,4 +129,20 @@ impl MpvCtl {
return Err("Did not get back an object".into());
}
}
pub async fn play_video<P: AsRef<Path>>(
&mut self,
path: P,
) -> Result<(), Box<dyn std::error::Error>> {
let request_id = self.grab_request_id();
let file_path = path.as_ref().to_str().unwrap().to_string();
let cmd = Command::new(vec!["loadfile".to_string(), file_path], Some(request_id));
let cmd_result = self.send_command(cmd).await?;
let result = cmd_result.await?;
if let serde_json::Value::Object(obj) = result {
return Ok(());
} else {
return Err("Did not get back an object".into());
}
}
}