Compare commits

..

No commits in common. "vlc" and "master" have entirely different histories.
vlc ... master

2 changed files with 76 additions and 66 deletions

View file

@ -50,9 +50,6 @@
<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,8 +24,6 @@ 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
{ {
@ -35,18 +33,15 @@ 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;
@ -85,34 +80,44 @@ namespace DMX2
bool Paused{ get; set;} bool Paused{ get; set;}
bool CheckVLC(){ 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;
mplayerProcess = Process.Start (startinfo);
mplayerProcess.OutputDataReceived += ProcessMplayerOut;
mplayerProcess.BeginOutputReadLine ();
return !mplayerProcess.HasExited;
}
return true; return true;
} }
void SendCommand(string command, string input) void ProcessMplayerOut (object sender, DataReceivedEventArgs e)
{ {
string url; string data = e.Data;
if (input != null) if (data == null)
{ return;
string encodedInput = Uri.EscapeDataString(input); if (data.StartsWith ("ANS_LENGTH")) {
url = $"{vlcUrl}?command={command}&input={encodedInput}"; string d = data.Substring (11);
} double dData;
else if(double.TryParse(d,NumberStyles.Number,CultureInfo.InvariantCulture,out dData))
url = $"{vlcUrl}?command={command}"; duration = TimeSpan.FromSeconds( dData );
}
try if (data.StartsWith ("ANS_TIME_POSITION")) {
{ string d = data.Substring (18);
string response = wc.DownloadString(url); double dData;
Console.WriteLine("Réponse VLC : " + response); if(double.TryParse(d,NumberStyles.Number,CultureInfo.InvariantCulture,out dData))
return; position = TimeSpan.FromSeconds( dData );
} }
catch (Exception e) Console.WriteLine ("data => {0}", data);
{ }
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)
{ {
@ -128,24 +133,28 @@ namespace DMX2
get{ return volume;} get{ return volume;}
set { set {
volume=value; volume=value;
uint val = volume * 255 / 100; if (mplayerProcess != null && !mplayerProcess.HasExited)
//if (mplayerProcess != null && !mplayerProcess.HasExited) {
//{ if (!Paused)
// if (!Paused) mplayerProcess.StandardInput.WriteLine("volume {0} 1", volume);
// 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 (CheckVLC ()) { if (CheckMplayer ()) {
mplayerProcess.StandardInput.WriteLine ("seek {0} 2", value.TotalMilliseconds / 1000);
} }
} }
} }
@ -170,21 +179,27 @@ namespace DMX2
curfile = files[pos]; curfile = files[pos];
Stop(); Stop();
//mplayerProcess.StandardInput.WriteLine ("volume 0 1"); // old
SendCommand("pl_empty", curfile); mplayerProcess.StandardInput.WriteLine ("volume {0} 1", volume);
mplayerProcess.StandardInput.WriteLine ("pausing loadfile \"{0}\"", curfile);
SendCommand("in_play", curfile); mplayerProcess.StandardInput.WriteLine ("pausing get_time_length");
//mplayerProcess.StandardInput.WriteLine("loadfile \"{0}\"", curfile); //old
Paused = true; //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;
} }
public void Play () public void Play ()
{ {
if (curfile==null || !Paused) if (curfile==null || !Paused)
return; return;
if (!CheckVLC ()) if (!CheckMplayer ())
return; return;
SendCommand("pl_play", null); mplayerProcess.StandardInput.WriteLine ("pause");
mplayerProcess.StandardInput.WriteLine ("volume {0} 1", volume);
Paused = false; Paused = false;
} }
@ -192,27 +207,21 @@ namespace DMX2
{ {
if (curfile==null || Paused) if (curfile==null || Paused)
return; return;
if (!CheckVLC ()) if (!CheckMplayer ())
return; return;
SendCommand("pl_pause", null); mplayerProcess.StandardInput.WriteLine ("pause");
Paused = true;
Paused = true;
} }
public void Stop () public void Stop ()
{ {
CheckVLC (); CheckMplayer ();
SendCommand("pl_stop", null); mplayerProcess.StandardInput.WriteLine ("stop");
}
} public SequenceurSon ()
public SequenceurSon ()
{ {
credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(":" + vlcPassword)); volumeEventTarget = new actionEventTargetEx (
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;
@ -455,7 +464,11 @@ 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
} }