Skip to content

Commit

Permalink
get_mpv_path
Browse files Browse the repository at this point in the history
  • Loading branch information
Fredolx committed Sep 28, 2024
1 parent 574890e commit c3c6832
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
34 changes: 34 additions & 0 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ r2d2 = "0.8.10"
bytes = "1.7.1"
tauri-plugin-dialog = "2.0.0-rc.1"
chrono = "0.4.38"
which = "6.0.3"
18 changes: 16 additions & 2 deletions src-tauri/src/mpv.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
use anyhow::{Context, Result};
use chrono::Local;
use directories::UserDirs;
use std::{path::Path, process::Stdio, time::Duration};
use which::which;
use std::{env::{consts::OS, current_exe}, path::Path, process::Stdio, time::Duration};
use tokio::{
io::{AsyncBufReadExt, BufReader},
process::Command,
time::timeout,
};
use std::sync::LazyLock;
use crate::{media_type, settings::get_settings, types::Channel};

const MPV_END_STR: [&str; 3] = ["AO", "VO", "AV"];
const ARG_SAVE_POSITION_ON_QUIT: &str = "--save-position-on-quit";
const ARG_CACHE: &str = "--cache";
const ARG_RECORD: &str = "--stream-record=";
static MPV_PATH: LazyLock<String> = LazyLock::new(|| get_mpv_path());

pub async fn play(channel: Channel, record: bool) -> Result<()> {
println!("{} playing", channel.url.as_ref().unwrap());
let args = get_play_args(channel, record)?;
let mut cmd = Command::new("mpv")
let mut cmd = Command::new(MPV_PATH.clone())
.args(args) // Add any arguments your command needs
.stdout(Stdio::piped())
.spawn()?;
Expand All @@ -34,6 +37,17 @@ pub async fn play(channel: Channel, record: bool) -> Result<()> {
Ok(())
}

fn get_mpv_path() -> String {
if OS != "windows" || which("mpv").is_ok() {
return "mpv".to_string();
}
let mut path = current_exe().unwrap();
path.pop();
path.push("deps");
path.push("mpv.exe");
return path.to_string_lossy().to_string();
}

//@TODO: Ask the user to set a custom recording path if default can't be found
fn get_play_args(channel: Channel, record: bool) -> Result<Vec<String>> {
let mut args = Vec::new();
Expand Down

0 comments on commit c3c6832

Please sign in to comment.