using System; using System.Diagnostics; namespace SingalDemo { public class OmxPlayer { private static Process Player; private static object lockObject = new object(); internal static void Play(string file) { lock (lockObject) { var args = $"-o local --loop {file}"; if (Player != null && !Player.HasExited && Player.StartInfo.Arguments == args) { Player.StandardInput.Write('p'); } else { try { if (Player != null && !Player.HasExited) { Player.StandardInput.Write('q'); Player.Kill(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } Player = new Process { StartInfo = new ProcessStartInfo { FileName = "omxplayer.bin", Arguments = args, RedirectStandardInput = true } }; Player.Start(); } } } internal static void Stop() { try { if (Player != null && !Player.HasExited) { Player.StandardInput.Write('q'); Player.Kill(); Process.Start("bash", "-c \"xrefresh -display :0\""); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } internal static void Pause() { if (Player != null && !Player.HasExited) { Player.StandardInput.Write('p'); } } internal static void SI() { Control("\x1b\x5b\x43"); } internal static void SD() { Control("\x1b\x5b\x44"); } internal static void VI() { Control("+"); } internal static void VD() { Control("-"); } internal static void Control(string command) { if (Player != null && !Player.HasExited) { Player.StandardInput.Write(command); } } } }