Compare commits

..

2 commits
master ... vlc

Author SHA1 Message Date
arnaud.houdelette
d7c1d4190f Exception sur fadeout 2025-06-17 16:56:48 +02:00
arnaud.houdelette
d37da1acaa Premiers jets 2025-06-17 16:22:05 +02:00
2 changed files with 66 additions and 76 deletions

View file

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

View file

@ -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<string> files = new List<string>();
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 (Exception 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
}