Premiers jets

This commit is contained in:
arnaud.houdelette 2025-06-17 16:22:05 +02:00
parent cb0a3ece4c
commit d37da1acaa
2 changed files with 66 additions and 76 deletions

View file

@ -50,6 +50,9 @@
<Package>gtk-sharp-2.0</Package> <Package>gtk-sharp-2.0</Package>
</Reference> </Reference>
<Reference Include="System.Web" /> <Reference Include="System.Web" />
<Reference Include="System.Net" />
<Reference Include="System.Web.Http" />
<Reference Include="Mono.Http" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="gtk-gui\gui.stetic"> <EmbeddedResource Include="gtk-gui\gui.stetic">

View file

@ -24,6 +24,8 @@ using System.Threading;
using System.Diagnostics; using System.Diagnostics;
using System.Xml; using System.Xml;
using System.Globalization; using System.Globalization;
using System.Net;
using System.Text;
namespace DMX2 namespace DMX2
{ {
@ -33,15 +35,18 @@ namespace DMX2
SeqSonUI ui=null; SeqSonUI ui=null;
Process mplayerProcess = null; //Process mplayerProcess = null;
List<string> files = new List<string>(); List<string> files = new List<string>();
string curfile = string.Empty; string curfile = string.Empty;
uint volume=100; uint volume=100;
System.Net.WebClient wc =new System.Net.WebClient();
String vlcPassword = "loupiottes";
string credentials;
string vlcUrl = "http://127.0.0.1:8080/requests/status.json";
TimeSpan fading=TimeSpan.Zero; TimeSpan fading=TimeSpan.Zero;
TimeSpan fadeLen; TimeSpan fadeLen;
@ -80,44 +85,34 @@ namespace DMX2
bool Paused{ get; set;} bool Paused{ get; set;}
bool CheckMplayer(){ bool CheckVLC(){
if (mplayerProcess == null || mplayerProcess.HasExited) {
if (mplayerProcess != null)
mplayerProcess.Dispose ();
ProcessStartInfo startinfo = new ProcessStartInfo ();
startinfo.FileName = "mplayer";
startinfo.Arguments = "-quiet -idle -slave";
startinfo.RedirectStandardInput = true;
startinfo.RedirectStandardOutput = true;
startinfo.UseShellExecute = false;
mplayerProcess = Process.Start (startinfo);
mplayerProcess.OutputDataReceived += ProcessMplayerOut;
mplayerProcess.BeginOutputReadLine ();
return !mplayerProcess.HasExited;
}
return true; return true;
} }
void ProcessMplayerOut (object sender, DataReceivedEventArgs e) void SendCommand(string command, string input)
{ {
string data = e.Data; string url;
if (data == null) if (input != null)
return; {
if (data.StartsWith ("ANS_LENGTH")) { string encodedInput = Uri.EscapeDataString(input);
string d = data.Substring (11); url = $"{vlcUrl}?command={command}&input={encodedInput}";
double dData; }
if(double.TryParse(d,NumberStyles.Number,CultureInfo.InvariantCulture,out dData)) else
duration = TimeSpan.FromSeconds( dData ); url = $"{vlcUrl}?command={command}";
}
if (data.StartsWith ("ANS_TIME_POSITION")) { try
string d = data.Substring (18); {
double dData; string response = wc.DownloadString(url);
if(double.TryParse(d,NumberStyles.Number,CultureInfo.InvariantCulture,out dData)) Console.WriteLine("Réponse VLC : " + response);
position = TimeSpan.FromSeconds( dData ); return;
} }
Console.WriteLine ("data => {0}", data); catch (WebException e)
} {
Console.WriteLine("Erreur lors de l'ajout du fichier : " + e.Message);
return;
}
}
public int AddFile (int pos, string file) public int AddFile (int pos, string file)
{ {
@ -133,28 +128,24 @@ namespace DMX2
get{ return volume;} get{ return volume;}
set { set {
volume=value; volume=value;
if (mplayerProcess != null && !mplayerProcess.HasExited) uint val = volume * 255 / 100;
{ //if (mplayerProcess != null && !mplayerProcess.HasExited)
if (!Paused) //{
mplayerProcess.StandardInput.WriteLine("volume {0} 1", volume); // if (!Paused)
} // mplayerProcess.StandardInput.WriteLine("volume {0} 1", volume);
//}
SendCommand($"volume&val={val}",null);
volumeEventTarget.FeedBack (); volumeEventTarget.FeedBack ();
} }
} }
public TimeSpan PlayTime { public TimeSpan PlayTime {
get{ get{
if (mplayerProcess != null && !mplayerProcess.HasExited)
{
if (!Paused)
mplayerProcess.StandardInput.WriteLine("get_time_pos");
}
return position; return position;
} }
set{ set{
if (CheckMplayer ()) { if (CheckVLC ()) {
mplayerProcess.StandardInput.WriteLine ("seek {0} 2", value.TotalMilliseconds / 1000);
} }
} }
} }
@ -179,27 +170,21 @@ namespace DMX2
curfile = files[pos]; curfile = files[pos];
Stop(); Stop();
//mplayerProcess.StandardInput.WriteLine ("volume 0 1"); // old
mplayerProcess.StandardInput.WriteLine ("volume {0} 1", volume); SendCommand("pl_empty", curfile);
mplayerProcess.StandardInput.WriteLine ("pausing loadfile \"{0}\"", curfile);
mplayerProcess.StandardInput.WriteLine ("pausing get_time_length"); SendCommand("in_play", curfile);
//mplayerProcess.StandardInput.WriteLine("loadfile \"{0}\"", curfile); //old
//mplayerProcess.StandardInput.WriteLine("get_time_length"); //old Paused = true;
////mplayerProcess.StandardInput.WriteLine ("pausing seek 0 2"); //old
//mplayerProcess.StandardInput.WriteLine ("pause"); //old
//mplayerProcess.StandardInput.WriteLine ("seek 0 2"); //old
//mplayerProcess.StandardInput.WriteLine ("volume {0} 1", volume); //old
Paused = true;
} }
public void Play () public void Play ()
{ {
if (curfile==null || !Paused) if (curfile==null || !Paused)
return; return;
if (!CheckMplayer ()) if (!CheckVLC ())
return; return;
mplayerProcess.StandardInput.WriteLine ("pause"); SendCommand("pl_play", null);
mplayerProcess.StandardInput.WriteLine ("volume {0} 1", volume);
Paused = false; Paused = false;
} }
@ -207,21 +192,27 @@ namespace DMX2
{ {
if (curfile==null || Paused) if (curfile==null || Paused)
return; return;
if (!CheckMplayer ()) if (!CheckVLC ())
return; return;
mplayerProcess.StandardInput.WriteLine ("pause"); SendCommand("pl_pause", null);
Paused = true;
Paused = true;
} }
public void Stop () public void Stop ()
{ {
CheckMplayer (); CheckVLC ();
mplayerProcess.StandardInput.WriteLine ("stop"); SendCommand("pl_stop", null);
}
public SequenceurSon () }
public SequenceurSon ()
{ {
volumeEventTarget = new actionEventTargetEx ( credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(":" + vlcPassword));
wc.Headers[HttpRequestHeader.Authorization] = "Basic " + credentials;
volumeEventTarget = new actionEventTargetEx (
delegate(EventData data) { delegate(EventData data) {
Volume = (uint)(100 * data.value / 255); Volume = (uint)(100 * data.value / 255);
return true; return true;
@ -464,11 +455,7 @@ namespace DMX2
#region IDisposable implementation #region IDisposable implementation
void IDisposable.Dispose () void IDisposable.Dispose ()
{ {
if (mplayerProcess != null && !mplayerProcess.HasExited) {
mplayerProcess.StandardInput.WriteLine ("quit");
if (!mplayerProcess.WaitForExit (1000))
mplayerProcess.Kill ();
}
} }
#endregion #endregion
} }