// FIXME: temp crutch, in testing on Mac OS X mplayer either terminates immediately or hangs, there is no in-between...
public void free()
  {
    currState = NO_STATE;
    if (Sage.DBG) System.out.println("Closing down mplayer");
    if (uiMgr != null)
      uiMgr.putFloat("mplayer/last_volume", currVolume);
    timeGuessMillis = 0;
    guessTimestamp = 0;
    currVolume = 1.0f;
    if (mpStdin != null && isMPlayerRunning())
    {
      // Be sure to clear the active file bit in case MPlayer is waiting for more data
      // Be sure we don't close the stdin connection before we send the quit message, but don't
      // hang waiting for the quit to be processed
      //			inactiveFile();
      //			stop();
      Thread t = new Thread("PlayerSendCmd")
      {
        public void run()
        {
          if (Sage.DBG) System.out.println("Waiting for the cmd queue to clear...");
          synchronized (sendCmdQueue)
          {
            while (!sendCmdQueue.isEmpty())
            {
              try
              {
                sendCmdQueue.wait(50);
              }
              catch (InterruptedException e){}
              continue;
            }
          }
          if (Sage.DBG) System.out.println("Sending mplayer command: quit");
          if (!fileDeactivated)
          {
            fileDeactivated = true;
            synchronized (mpStdin)
            {
              mpStdin.println("inactive_file");
            }
          }
          if (currState == PLAY_STATE && !eos)
          {
            synchronized (mpStdin)
            {
              mpStdin.println("pause");
            }
            currState = STOPPED_STATE;
          }
          else
            currState = STOPPED_STATE;
          synchronized (mpStdin)
          {
            mpStdin.println("quit");
          }
          mpStdin.close();
          mpStdin = null;
          if (mpStdout != null)
          {
            try { mpStdout.close(); } catch (java.io.IOException e) {}
            mpStdout = null;
          }
          if (mpStderr != null)
          {
            try { mpStderr.close(); } catch (java.io.IOException e) {}
            mpStderr = null;
          }
        }
      };
      t.setPriority(Thread.currentThread().getPriority());
      t.setDaemon(true);
      t.start();
    }
    if (mpProc != null)
    {
      long startWait = Sage.eventTime();
      // FIXME: temp crutch, in testing on Mac OS X mplayer either terminates immediately or hangs, there is no in-between...
      long killDelay = (Sage.MAC_OS_X ? 2000 : 15000);
      while (true)
      {
        try
        {
          int exitValue = mpProc.exitValue();
          if (Sage.DBG) System.out.println("MPlayer process exit code:" + exitValue);
          break;
        }
        catch (IllegalThreadStateException e)
        {
          if (Sage.DBG) System.out.println("MPlayer process has not exited yet...");
          try{Thread.sleep(100);}catch(Exception e1){}
          if (Sage.eventTime() - startWait > killDelay)
          {
            if (Sage.DBG) System.out.println("Forcibly killing MPlayer process!");
            mpProc.destroy();
            break;
          }
        }
      }
      mpProc = null;
    }
    if (launchedAsyncRenderThread)
      ((DirectX9SageRenderer)uiMgr.getRootPanel().getRenderEngine()).asyncVideoRender(null);
    if (releaseServerAccessVobSubBase != null)
    {
      NetworkClient.getSN().requestMediaServerAccess(new java.io.File(releaseServerAccessVobSubBase + ".idx"), false);
      NetworkClient.getSN().requestMediaServerAccess(new java.io.File(releaseServerAccessVobSubBase + ".sub"), false);
      releaseServerAccessVobSubBase = null;
    }
  }
{
long startWait = Sage.eventTime();
// FIXME: temp crutch, in testing on Mac OS X mplayer either terminates immediately or hangs, there is no in-between...
long killDelay = (Sage.MAC_OS_X ? 2000 : 15000);
while (true)
}
}
};
t.setPriority(Thread.currentThread().getPriority());
t.setDaemon(true);
t.start();
}
if (mpProc != null)
{
long startWait = Sage.eventTime();
// FIXME: temp crutch, in testing on Mac OS X mplayer either terminates immediately or hangs, there is no in-between...
long killDelay = (Sage.MAC_OS_X ? 2000 : 15000);
while (true)
{
try
{
int exitValue = mpProc.exitValue();
if (Sage.DBG) System.out.println("MPlayer process exit code:" + exitValue);
break;
}
catch (IllegalThreadStateException e)
mpStdin = null;
if (mpStdout != null)
{
try { mpStdout.close(); } catch (java.io.IOException e) {}
mpStdout = null;
}
if (mpStderr != null)
{
try { mpStderr.close(); } catch (java.io.IOException e) {}
mpStderr = null;
}
}
};
t.setPriority(Thread.currentThread().getPriority());
t.setDaemon(true);
t.start();
}
if (mpProc != null)
{
long startWait = Sage.eventTime();
// FIXME: temp crutch, in testing on Mac OS X mplayer either terminates immediately or hangs, there is no in-between...
long killDelay = (Sage.MAC_OS_X ? 2000 : 15000);
while (true)
{
try
{
int exitValue = mpProc.exitValue();
if (Sage.DBG) System.out.println("MPlayer process exit code:" + exitValue);
break;
}
catch (IllegalThreadStateException e)
{
if (Sage.DBG) System.out.println("MPlayer process has not exited yet...");
try{Thread.sleep(100);}catch(Exception e1){}
if (Sage.eventTime() - startWait > killDelay)
{
if (Sage.DBG) System.out.println("Forcibly killing MPlayer process!");
mpProc.destroy();
break;
}
}