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;
    }
  }
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())
    {
     
     
     
     
     
      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();
     
      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;
    }
  }
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()) { 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(); 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; } }