I have a line of code that is supposed to get the current status / track from Winamp

passthru("C:/htdocs/lib/winampinfo.exe");

the output when it is run from command prompt is

<b>Status:</b> Winamp is rocking it!
<b>Time on Track:</b> 6 seconds
<b>Currently:</b> Injected - Faithless

but PHP only returns

Winamp is not running! :O

the error message thrown by the exception if a Winamp instance is not running.

This is the C# for the prog:

using System;
using System.Runtime.InteropServices;
using System.IO;

namespace WinampInfo
{
 /// <summary>
 /// Summary description for Class1.
 /// </summary>
 public class WinampControl
 {
  public WinampControl()
  {
   WINDOW_HANDLER = FindWindow("Winamp v1.x",null);
   if(WINDOW_HANDLER == 0)
   {
    throw new Exception("Winamp is not running! :O");
   }
  }
  
  private int WINDOW_HANDLER;
  private const int WM_COMMAND = 0x111;
  private const int WM_USER = 0x400;

  public const int WINAMP_ISPLAYING = 104;
  public const int WINAMP_TIMEGOING = 105;
  public const int WINAMP_WRITE_POSITION = 120;
  
  [DllImport("user32.dll",EntryPoint="SendMessage")]
  private static extern int SendMessage(int _WindowHandler, int _WM_USER, int _data, 
int _id);
  
  [DllImport("user32.dll",EntryPoint="FindWindow")]
  private static extern int FindWindow(string _ClassName, string _WindowName);
  
  public void SendCommands()
  {
   int intRetWINAMP_ISPLAYING = 0;
   int intRetWINAMP_TIMEGOING = 0;
   int intRetWINAMP_WRITE_POSITION = 0;
   intRetWINAMP_ISPLAYING = SendMessage(WINDOW_HANDLER,WM_USER,0,WINAMP_ISPLAYING);
   string strPlayStatus = null;
   string strPlayTime = null;
   string strPlaySong = null;
   switch (intRetWINAMP_ISPLAYING)
   {
    case (1):
     strPlayStatus = "Winamp is rocking it!";
     break;
    case (3):
     strPlayStatus = "Winamp is paused.";
     break;
    default:
     strPlayStatus = "Winamp is stopped.";
     break;
   }
   intRetWINAMP_TIMEGOING = SendMessage(WINDOW_HANDLER,WM_USER,0,WINAMP_TIMEGOING);
   long lngRetWINAMP_TIMEGOING = intRetWINAMP_TIMEGOING;
   if (lngRetWINAMP_TIMEGOING >= 60000)
   {
    if ((lngRetWINAMP_TIMEGOING / 60000.0) == Math.Floor(lngRetWINAMP_TIMEGOING / 
60000))
    {
     if ((lngRetWINAMP_TIMEGOING / 60000) == 1)
     {
      strPlayTime = "1 minute";
     } 
     else
     {
      strPlayTime = (lngRetWINAMP_TIMEGOING / 60000).ToString() + " minutes";
     }
    } 
    else
    {
     if ((lngRetWINAMP_TIMEGOING / 60000) == 1)
     {
      strPlayTime = "1 minute";
     } 
     else
     {
      strPlayTime = (lngRetWINAMP_TIMEGOING / 60000).ToString() + " minutes";
     }
     if (((intRetWINAMP_TIMEGOING % 60000) / 1000) == 1)
     {
      strPlayTime += " and 1 second";
     }
     else
     {
      if (((intRetWINAMP_TIMEGOING / 1000) % 60) != 0)
      {
       strPlayTime += " and " + ((lngRetWINAMP_TIMEGOING / 1000) - 
(lngRetWINAMP_TIMEGOING / 60000) * 60).ToString() + " seconds";
      }
     }
    }
   }
   else
   {
    if ((lngRetWINAMP_TIMEGOING / 1000) == 1)
    {
     strPlayTime = "1 second";
    }
    else
    {
     strPlayTime = (lngRetWINAMP_TIMEGOING / 1000).ToString() + " seconds";
    }
   }

   intRetWINAMP_WRITE_POSITION = 
SendMessage(WINDOW_HANDLER,WM_USER,0,WINAMP_WRITE_POSITION);
   string strPlaylistFile = "C:/program files/winamp/winamp.m3u";

   if (!File.Exists(strPlaylistFile)) strPlaySong = "Unable to open the playlist for 
parsing.";
   StreamReader sr = File.OpenText(strPlaylistFile);
   string strInput;
   int intCntr = 0;
   int intLine2Read = intRetWINAMP_WRITE_POSITION * 2 + 1;
   for (intCntr = 0; intCntr <= intLine2Read; intCntr++) 
   {
    strInput=sr.ReadLine();
    if ((intCntr == intLine2Read) && (strInput != null))
    {
     string[] strInfo = strInput.Split(new Char[] {','},2);
     strPlaySong = strInfo[1];
    }
   }
   Console.WriteLine("<b>Status:</b> " + strPlayStatus);
   Console.WriteLine("<b>Time on Track:</b> " + strPlayTime);
   Console.WriteLine("<b>Currently:</b> " + strPlaySong);
  }
 }

 class Class1
 {
  /// <summary>
  /// The main entry point for the application.
  /// </summary>
  [STAThread]
  static void Main(string[] args)
  {
   try
   {
    WinampControl myControl = new WinampControl();
    myControl.SendCommands();
   }
   
   catch(Exception e)
   {
    Console.WriteLine(e.Message);
   }
   
   finally
   {
    Console.WriteLine("<!-- Made with Visual Studio .NET by Devon Knowles -->");
   }

  }
 }
}

If anyone has any idea why this isn't working, I'd appreciate the help. I really don't 
want to have to output to a text file and then have to read it again in my script.

- Devon Knowles
[EMAIL PROTECTED]

Reply via email to