From d37da1acaac370900aa447be3d1635596468f998 Mon Sep 17 00:00:00 2001 From: "arnaud.houdelette" Date: Tue, 17 Jun 2025 16:22:05 +0200 Subject: [PATCH] Premiers jets --- DMX-2.0/DMX-2.0.csproj | 3 + DMX-2.0/SequenceurSon.cs | 139 ++++++++++++++++++--------------------- 2 files changed, 66 insertions(+), 76 deletions(-) diff --git a/DMX-2.0/DMX-2.0.csproj b/DMX-2.0/DMX-2.0.csproj index 1167d22..5247eea 100644 --- a/DMX-2.0/DMX-2.0.csproj +++ b/DMX-2.0/DMX-2.0.csproj @@ -50,6 +50,9 @@ gtk-sharp-2.0 + + + diff --git a/DMX-2.0/SequenceurSon.cs b/DMX-2.0/SequenceurSon.cs index 093ec57..d83bc55 100644 --- a/DMX-2.0/SequenceurSon.cs +++ b/DMX-2.0/SequenceurSon.cs @@ -24,6 +24,8 @@ using System.Threading; using System.Diagnostics; using System.Xml; using System.Globalization; +using System.Net; +using System.Text; namespace DMX2 { @@ -33,15 +35,18 @@ namespace DMX2 SeqSonUI ui=null; - Process mplayerProcess = null; + //Process mplayerProcess = null; List files = new List(); string curfile = string.Empty; 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 fadeLen; @@ -80,44 +85,34 @@ namespace DMX2 bool Paused{ get; set;} - bool CheckMplayer(){ - 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; + bool CheckVLC(){ - mplayerProcess = Process.Start (startinfo); - mplayerProcess.OutputDataReceived += ProcessMplayerOut; - mplayerProcess.BeginOutputReadLine (); - return !mplayerProcess.HasExited; - } return true; } - void ProcessMplayerOut (object sender, DataReceivedEventArgs e) - { - string data = e.Data; - if (data == null) - return; - if (data.StartsWith ("ANS_LENGTH")) { - string d = data.Substring (11); - double dData; - if(double.TryParse(d,NumberStyles.Number,CultureInfo.InvariantCulture,out dData)) - duration = TimeSpan.FromSeconds( dData ); - } - if (data.StartsWith ("ANS_TIME_POSITION")) { - string d = data.Substring (18); - double dData; - if(double.TryParse(d,NumberStyles.Number,CultureInfo.InvariantCulture,out dData)) - position = TimeSpan.FromSeconds( dData ); - } - Console.WriteLine ("data => {0}", data); - } + void SendCommand(string command, string input) + { + string url; + if (input != null) + { + string encodedInput = Uri.EscapeDataString(input); + url = $"{vlcUrl}?command={command}&input={encodedInput}"; + } + else + url = $"{vlcUrl}?command={command}"; + + try + { + string response = wc.DownloadString(url); + Console.WriteLine("Réponse VLC : " + response); + return; + } + catch (WebException e) + { + Console.WriteLine("Erreur lors de l'ajout du fichier : " + e.Message); + return; + } + } public int AddFile (int pos, string file) { @@ -133,28 +128,24 @@ namespace DMX2 get{ return volume;} set { volume=value; - if (mplayerProcess != null && !mplayerProcess.HasExited) - { - if (!Paused) - mplayerProcess.StandardInput.WriteLine("volume {0} 1", volume); - } + uint val = volume * 255 / 100; + //if (mplayerProcess != null && !mplayerProcess.HasExited) + //{ + // if (!Paused) + // mplayerProcess.StandardInput.WriteLine("volume {0} 1", volume); + //} + SendCommand($"volume&val={val}",null); volumeEventTarget.FeedBack (); } } public TimeSpan PlayTime { get{ - if (mplayerProcess != null && !mplayerProcess.HasExited) - { - if (!Paused) - mplayerProcess.StandardInput.WriteLine("get_time_pos"); - - } + return position; } set{ - if (CheckMplayer ()) { - mplayerProcess.StandardInput.WriteLine ("seek {0} 2", value.TotalMilliseconds / 1000); + if (CheckVLC ()) { } } } @@ -179,27 +170,21 @@ namespace DMX2 curfile = files[pos]; Stop(); - //mplayerProcess.StandardInput.WriteLine ("volume 0 1"); // old - mplayerProcess.StandardInput.WriteLine ("volume {0} 1", volume); - mplayerProcess.StandardInput.WriteLine ("pausing loadfile \"{0}\"", curfile); - mplayerProcess.StandardInput.WriteLine ("pausing get_time_length"); - //mplayerProcess.StandardInput.WriteLine("loadfile \"{0}\"", curfile); //old - //mplayerProcess.StandardInput.WriteLine("get_time_length"); //old - ////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; + + SendCommand("pl_empty", curfile); + + SendCommand("in_play", curfile); + + Paused = true; } public void Play () { if (curfile==null || !Paused) return; - if (!CheckMplayer ()) + if (!CheckVLC ()) return; - mplayerProcess.StandardInput.WriteLine ("pause"); - mplayerProcess.StandardInput.WriteLine ("volume {0} 1", volume); + SendCommand("pl_play", null); Paused = false; } @@ -207,21 +192,27 @@ namespace DMX2 { if (curfile==null || Paused) return; - if (!CheckMplayer ()) + if (!CheckVLC ()) return; - mplayerProcess.StandardInput.WriteLine ("pause"); - Paused = true; + SendCommand("pl_pause", null); + + Paused = true; } public void Stop () { - CheckMplayer (); - mplayerProcess.StandardInput.WriteLine ("stop"); - } + CheckVLC (); + 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) { Volume = (uint)(100 * data.value / 255); return true; @@ -464,11 +455,7 @@ namespace DMX2 #region IDisposable implementation void IDisposable.Dispose () { - if (mplayerProcess != null && !mplayerProcess.HasExited) { - mplayerProcess.StandardInput.WriteLine ("quit"); - if (!mplayerProcess.WaitForExit (1000)) - mplayerProcess.Kill (); - } + } #endregion }