Writing Your First Script
This section will show you how to use the WinampCOM library in a variety of scripting languages. The function reference will show you more information on each individual function. The examples in the reference section are all written in JScript but they should be easily adaptable to any language.
GetPlaylist has examples in more languages because the implementation is less obvious in some langauges.
Every program should start by testing the result of GetVersionString to check the existence of winamp. If this function fails then the results of all other functions except GetErrorLog are undefined.
JScript
var winamp = new ActiveXObject( "WinampCOM.Winamp" );
if (winamp.GetVersionString() == 0)
{
WScript.Echo("Winamp not found");
// for more information, uncomment the next line
// WScript.Echo(winamp.GetErrorLog());
}
else
{
// ...
}
VBScript
Dim winamp
Set winamp = WScript.CreateObject("WinampCOM.winamp")
If winamp.GetVersionString() = "0.000" Then
WScript.Echo "Winamp Not Found"
' For extended error information uncomment the next line
' WScript.Echo winamp.GetErrorLog()
Else
' ...
End If
PHP
echo "<html><head><title>Winamp Remote</title></head><body>\n";
$winamp = new COM('WinampCOM.Winamp');
if ($winamp->GetVersionString() == 0)
{
echo "<p><b>error: unable to connect to winamp</b></p>\n";
// to get extended error information, uncomment the following line
echo htmlspecialchars($winamp->GetErrorLog());
echo "</body></html>\n";
exit;
}
// ...
PHP / Apache Users Take Note: See Using WinampCOM with Apache/PHP
Python
To use WinampCOM from within Python, you need to install Mark Hammond Win32
Python bindings. This can be downloaded from www.python.org.
import sys
import win32com.client
winamp = win32com.client.Dispatch("WinampCOM.winamp")
if winamp.GetVersionString() == "0.000" :
print "Winamp not found, error log follows : "
# for more information, uncomment the next line
# print winamp.GetErrorLog()
sys.exit(1)
# ...