You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iot/labs/IoTServices/SingalDemo/OmxPlayer.cs

105 lines
2.9 KiB

using System;
using System.Diagnostics;
using System.IO;
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 = $"{Startup.Configuration["omx"]} {file}";
Console.WriteLine(args);
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",
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("+");
Process.Start("bash", $"-c \"{Path.Combine(Startup.Env.WebRootPath, "omx.sh")} 0.1\"");
}
internal static void VD()
{
//Control("-");
Process.Start("bash", $"-c \"{Path.Combine(Startup.Env.WebRootPath, "omx.sh")} -0.1\"");
}
internal static void Control(string command)
{
if (Player != null && !Player.HasExited)
{
Player.StandardInput.Write(command);
}
}
}
}