private void StartMPlayer(string sFileName)
{
lock (_Serializer)
{
// Wait if the last process signals finish.
if (_MPlayerProcess != null)
{
MessageBox.Show(
this,
"MPlayer still running",
"Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}
MPlayerStartUIConfig();
// Process related.
_FormInstance = this;
_dMPlayerStartTime = -1;
_dCurrentTrimTime = 0;
// Find MPlayer executable, either by user setting or in TsRemux.exe dir.
AppSettingsReader Config = new AppSettingsReader();
string sMPlayerExe = (string)Config.GetValue("MPlayerExe", typeof(string));
// Check if configured exe exists.
if (!File.Exists(sMPlayerExe))
{
// Try to find one in startup dir.
sMPlayerExe = Path.Combine(Application.StartupPath, "mplayer.exe");
if (!File.Exists(sMPlayerExe))
{
MessageBox.Show(
this,
"MPlayer executable missing.",
"Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}
}
// Read user settings ...
string sMPlayerCmdLine = (string)Config.GetValue("MPlayerCmdLine", typeof(string));
// Append HWND from our picture box.
sMPlayerCmdLine += string.Format(" -wid {0}", MPlayerPreview.Handle);
// Need slave mode for control.
sMPlayerCmdLine += " -loop 0 -slave";
// Build file component.
string sFile = "\"" + sFileName + "\"";
// Create and configure process.
try
{
_MPlayerProcess = new Process();
_MPlayerProcess.StartInfo.FileName = sMPlayerExe;
_MPlayerProcess.StartInfo.Arguments = sMPlayerCmdLine + " " + sFile;
_MPlayerProcess.StartInfo.UseShellExecute = false;
_MPlayerProcess.StartInfo.CreateNoWindow = true;
_MPlayerProcess.StartInfo.RedirectStandardOutput = true;
_MPlayerProcess.OutputDataReceived += new DataReceivedEventHandler(CaptureMPlayer);
_MPlayerProcess.StartInfo.RedirectStandardInput = true;
/*
_MPlayerProcess.SynchronizingObject = this;
_MPlayerProcess.EnableRaisingEvents = true;
_MPlayerProcess.Exited += new EventHandler(MPlayerFinished);
*/
_MPlayerProcess.Start();
_MPlayerProcess.BeginOutputReadLine();
}
catch (Exception)
{
MessageBox.Show(
this,
"MPlayer can't be started.",
"Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
_MPlayerProcess = null;
return;
}
// Start timer to update UI.
TrimSetTimer.Enabled = true;
}
}